import boto3 import json import uuid def lambda_handler(event, context): s3 = boto3.client('s3') try: job_id = uuid.uuid1() bucket_name = event['bucket'] file_name = event['file'] config_raw = s3.get_object(Bucket=bucket_name, Key=file_name) config_str = config_raw['Body'].read().decode('utf-8') config_json = json.loads(config_str) aws_bucket = config_json['aws_config']['bucket'] aws_file = config_json['aws_config']['file'] aws_raw = s3.get_object(Bucket=aws_bucket, Key=aws_file) aws_str = aws_raw['Body'].read().decode('utf-8') aws_json = json.loads(aws_str) return { "job_id" : str(job_id), "status" : "SUCCESS", "command": [ "--url=" + config_json['content_source'], "--s3-bucket=" + config_json['s3_destination'] ], "launch_type" : aws_json['LaunchType'], "subnets" : aws_json['Subnets'], "cluster" : aws_json['Cluster'], "task_definition" : aws_json['TaskDefinition'] } except Exception as e: return { "status" : "FAILURE", "exception" : str(e) }