""" This is for usage with the altafonte user creation step function. It retrieves the email addresses from failed executions given a map run arn. Uhhhh run somewhere that you have boto3 installed and make sure you've awsumed prod. """ import boto3 import json def get_failed_execution_emails(map_run_arn): """ Get email addresses from failed executions in a Step Functions map run. Args: map_run_arn: ARN of the map run Returns: List of email addresses from failed executions """ sfn_client = boto3.client('stepfunctions') failed_emails = [] next_token = None # Paginate through all failed executions in the map run while True: kwargs = { 'mapRunArn': map_run_arn, 'statusFilter': 'FAILED' } if next_token: kwargs['nextToken'] = next_token response = sfn_client.list_executions(**kwargs) # Process each failed execution for execution in response.get('executions', []): # Get execution details to access the input execution_details = sfn_client.describe_execution( executionArn=execution['executionArn'] ) # Parse the input JSON and extract the email field input_data = json.loads(execution_details['input']) if 'email' in input_data: failed_emails.append(input_data['email']) # Check if there are more results next_token = response.get('nextToken') if not next_token: break return failed_emails