"""Lambda main module.""" import sentry_sdk from lambdacommon.common_config import logger from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from src import config from src import utils from src import logic if config.SENTRY_DSN: logger.info('Initializing with sentry') sentry_sdk.init( config.SENTRY_DSN, integrations=[AwsLambdaIntegration()] ) else: logger.info('Initializing without sentry') def handler_single(event): """Handle single event.""" logger.info(f'Processing event: {event}') asset_final = utils.FinalAsset(**event) if not asset_final.filename.endswith('.wav'): raise ValueError(f'Not a wav s3 file: "{asset_final.filename}"') result = logic.download_and_process( bucket=asset_final.bucket, key=asset_final.filename ) logic.produce_kafka_event(asset_final, result) logger.info('Processing complete') def handler(event, context): """Lambda entry point.""" for n, single_event in enumerate(utils.get_events_from_batch(event)): logger.info(f'Event #{n}') try: handler_single(single_event) except: # noqa: E722 pass return {'status': 'OK'}