"""Logic for step functions.""" from functools import cache import json import time import boto3 from src import config @cache def get_sfn_client(): """Get Step Functions client.""" return boto3.client('stepfunctions', config.AWS_REGION) def invoke_auto_approval_sfn(execution_input): """Start execution of auto-appoval step function.""" execution_arn = None review_id = execution_input.get('data', {}).get('review_queue_id') kwargs = { 'stateMachineArn': config.AUTO_APPROVE_STEP_FUNC_ARN, 'input': json.dumps(execution_input), 'name': f'auto-approve-{int(time.time())}-review-queue-{review_id}', } try: sfn_client = get_sfn_client() response = sfn_client.start_execution(**kwargs) execution_arn = response.get('executionArn') if response else None except Exception as e: raise Exception(f'Failed to start step function: {str(e)}') return execution_arn