"""Amazon Step Functions Connector.""" import boto3 from botocore.config import Config from mypy_boto3_stepfunctions import SFNClient from mypy_boto3_stepfunctions.type_defs import StartExecutionOutputTypeDef from video import config from video.constants import job_types WORKFLOW_JOB_TYPE_TO_STATE_MACHINE_ARN = { job_types.WORKFLOW_INGEST_FROM_BROWSER: ( config.VIDEO_INGESTION_WORKFLOW_STATE_MACHINE_ARN ), job_types.WORKFLOW_INGEST_FROM_S3: ( config.VIDEO_INGESTION_WORKFLOW_STATE_MACHINE_ARN ), job_types.WORKFLOW_INGEST_FROM_GOOGLE_DRIVE: ( config.VIDEO_INGESTION_WORKFLOW_STATE_MACHINE_ARN ), job_types.WORKFLOW_INGEST_FROM_DROPBOX: ( config.VIDEO_INGESTION_WORKFLOW_STATE_MACHINE_ARN ), job_types.WORKFLOW_APPROVAL: (config.VIDEO_APPROVAL_WORKFLOW_STATE_MACHINE_ARN), job_types.WORKFLOW_INGESTION_REENCODE: ( config.VIDEO_INGESTION_REENCODE_WORKFLOW_STATE_MACHINE_ARN ), } def get_stepfunctions_client() -> SFNClient: """Get stepfunctions client.""" return boto3.client( "stepfunctions", region_name=config.AWS_REGION, config=Config(read_timeout=70), ) def start_execution( execution_input: str, execution_name: str, workflow_job_type: str ) -> StartExecutionOutputTypeDef: """Start a state machine execution.""" state_machine_arn = WORKFLOW_JOB_TYPE_TO_STATE_MACHINE_ARN.get(workflow_job_type) if not state_machine_arn: raise ValueError( f"No state machine ARN configured for job type: {workflow_job_type}" ) return get_stepfunctions_client().start_execution( input=execution_input, name=execution_name, stateMachineArn=state_machine_arn )