def lambda_handler()

in ApplicationCode/dockerfiles/routing-lambda/src/lambda_function.py [0:0]


def lambda_handler(event, context):
    try:
        print(json.dumps(event))
        logger.info('Received {} messages'.format(len(event['Records'])))
        for record in event['Records']:
            logger.info('Parsing S3 Event')
            message = parse_s3_event(json.loads(record['body'])['Records'][0])

            if os.environ['NUM_BUCKETS'] == '1':
                team = message['key'].split('/')[1]
                dataset = message['key'].split('/')[2]
            elif len(message['key'].split('/')) == 5:
                team = message['key'].split('/')[0]
                dataset = message['key'].split(
                    '/')[1] + '-' + message['key'].split('/')[2]
                partition = message['key'].split('/')[-2]
            else:
                team = message['key'].split('/')[0]
                dataset = message['key'].split('/')[1]
                partition = message['key'].split('/')[-2]
            message['team'] = team
            message['dataset'] = dataset
            pipeline = get_item(dataset_table, team, dataset)
            message['pipeline'] = pipeline
            message['partition'] = partition
            runtime_region = os.environ['AWS_REGION']
            print(runtime_region)
            logger.info(
                'Sending event to {}-{} pipeline queue for processing'.format(team, pipeline))
            a = '{}-{}-{}-{}-{}-{}-queue-a.fifo'.format(
                'sdlf',
                team,
                pipeline,
                os.environ['ORG'],
                os.environ['APP'],
                os.environ['ENV']
                # team,
                # pipeline
            )
            print(a)
            queue = sqs.get_queue_by_name(QueueName='{}-{}-{}-{}-{}-{}-queue-a.fifo'.format(
                'sdlf',
                team,
                pipeline,
                os.environ['ORG'],
                os.environ['APP'],
                os.environ['ENV']
                # team,
                # pipeline
            ))
            print(queue)
            runtime_region = os.environ['AWS_REGION']
            print(runtime_region)
            queue.send_message(MessageBody=json.dumps(
                message), MessageGroupId='{}-{}'.format(team, dataset), MessageDeduplicationId=str(uuid.uuid1()))
    except Exception as e:
        logger.error("Fatal error", exc_info=True)
        raise e
    return