def handle()

in codes/lambda/mlops-trigger-statemachine/src/handler.py [0:0]


def handle(event, context):
    print('event--->', event)

    client = boto3.client('stepfunctions')

    for record in event['Records']:
        bucket_name: str = record['s3']['bucket']['name']
        input_file_key: str = record['s3']['object']['key']
        print('etl_input_file_key => {}'.format(input_file_key))
        
        if input_file_key.find('.') > -1:
            temp = input_file_key.replace(f'{_bucket_key_for_input}/', f'{_bucket_key_for_output}/', 1)
            output_dir_key = temp.split('.')[0]

            temp = output_dir_key.replace(f'{_bucket_key_for_output}/', '', 1)
            temp = temp.replace("/", "-")
            execution_name = f'{_endpoint_name}-{temp}'

            request = get_request_template()
            request['PreprocessGlue']['--S3_INPUT_FILE'] = f's3://{bucket_name}/{input_file_key}'
            request['PreprocessGlue']['--S3_TRAIN_KEY'] = f's3://{bucket_name}/{output_dir_key}/data/train/'
            request['PreprocessGlue']['--S3_VALIDATE_KEY'] = f's3://{bucket_name}/{output_dir_key}/data/validate/'
            
            request['TrainSageMaker']['TrainingJobName'] = execution_name
            request['TrainSageMaker']['TrainData'] = request['PreprocessGlue']['--S3_TRAIN_KEY']
            request['TrainSageMaker']['ValidateData'] = request['PreprocessGlue']['--S3_VALIDATE_KEY']
            request['TrainSageMaker']['TrainOutput'] = f's3://{bucket_name}/{output_dir_key}/model/'
            
            request['ServeSageMaker']['ModelName'] = execution_name
            request['ServeSageMaker']['EndpointConfigName'] = execution_name
            request['ServeSageMaker']['EndpointName'] = _endpoint_name

            trigger_statemachine(client, execution_name, _statemachine_arn, request)