"""Step function logic.""" from functools import cache import json import time import uuid import boto3 from src import config @cache def get_sfn_client(): """Get Step Functions client.""" return boto3.client('stepfunctions', config.AWS_REGION) def trigger_sfn(execution_input): """Trigger step function for indexing review queue items.""" kwargs = { 'stateMachineArn': config.STEP_FUNCTION_ARN, 'input': json.dumps(execution_input), 'name': f'index-product-metadata-{str(uuid.uuid4())}-{str(int(time.time()))}', } stepfn_client = get_sfn_client() try: response = stepfn_client.start_execution(**kwargs) except Exception as e: raise Exception(f'Failed to start step function: {e}, input: {execution_input}') return response