"""SFN Connector.""" import json from functools import lru_cache import boto3 from product_review import config @lru_cache(maxsize=None) def get_sfn_client(): """Get SFN client.""" return boto3.client("stepfunctions", config.AWS_REGION) def trigger_sfn(sfn_arn, execution_name, payload): """Trigger step function execution.""" sfn_client = get_sfn_client() try: response = sfn_client.start_execution( **{ "stateMachineArn": sfn_arn, "input": json.dumps(payload), "name": execution_name, } ) except sfn_client.exceptions.ExecutionAlreadyExists as e: return False, e return True, response