"""Multiplexer lambda sample. This lambda is triggered by an s3 PutObject event and receives an S3 event message with information about uploaded file. This function computes the type of transcoding for uploaded file. """ IMAGE_TYPES = ['jpg', 'jpeg', 'png', 'tif'] AUDIO_TYPES = ['flac', 'wav', 'm4a'] def handler(event, context): """Lambda handler. Args: event: (dict): PutObjectMessage. context: (dict): Environment state. Returns: dict: Dict with information about file and transcoding type code. """ key = event['detail']['requestParameters']['key'].lower() bucket = event['detail']['requestParameters']['bucketName'] if any([i in key for i in IMAGE_TYPES]): return {'result': 1, 'key': key, 'bucket': bucket} elif any([a in key for a in AUDIO_TYPES]): return {'result': 2, 'key': key, 'bucket': bucket} return {'result': 3, 'key': key, 'bucket': bucket} # Unknown type