"""Lambda ar-fingerprint-filter function module.""" import os from .common import logger import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration import config from .utils.events import filter_events from .utils.events import generate_outputs from .utils.records import decode_records from .utils.sfn_handler import throttle from .utils.sfn_handler import execute_sfn from src.common.connectors.sfn import sfn_client # initialize sentry sentry_dsn = os.environ.get('SENTRY_DSN', config.secrets_manager_client.get_cred('SENTRY_DSN')) if sentry_dsn: logger.info('Initializing with sentry') sentry_sdk.init( sentry_dsn, integrations=[AwsLambdaIntegration()] ) else: logger.info('Initializing without sentry') def handler(event, context): """Lambda entry point.""" try: logger.info(event) all_events = decode_records(event) filtered_events = filter_events(all_events) output_events = generate_outputs(filtered_events) exc_names: dict[str, list[str]] = { 'skipped': [], 'started': [] } throttle(sfn_client, len(output_events)) for event in output_events: (exc_name, started) = execute_sfn(sfn_client, event) if started: exc_names['started'].append(exc_name) else: exc_names['skipped'].append(exc_name) summary = { 'num_input_records': len(all_events), 'sfn_executions': exc_names } logger.info(summary) return summary except Exception as e: logger.exception(str(e)) raise e