"""Lambda generate_flowthorugh_adjustments function module.""" from __future__ import annotations from datetime import datetime from typing import Any, Mapping import sentry_sdk from lambdacommon.common_config import logger from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from snowflake_connector.etl_connector import SnowflakeSQLExecutor import config from generate_flowthrough_adjustments.processor import ( GenerateFlowthroughAdjustmentsProcessor, ) if config.SENTRY_DSN: sentry_sdk.init( dsn=config.SENTRY_DSN, environment=config.ENVIRONMENT, integrations=[AwsLambdaIntegration(timeout_warning=True)], ) def handler(event: Mapping[str, Any] | None, context: Any) -> dict[str, Any]: """Lambda entry point. Args: event: Event data passed to the Lambda function. context: Lambda runtime information. Returns: dict: Response with batch_id, correlation_id, s3_bucket, and s3_key. """ try: logger.info(f'Function ARN: {context.invoked_function_arn}') with SnowflakeSQLExecutor(config.SNOWFLAKE_CONFIG) as sf_executor: processor = GenerateFlowthroughAdjustmentsProcessor(event, sf_executor) start_time = datetime.now() total_flowthrough_count = processor.process() end_time = datetime.now() diff = end_time - start_time print(f'Finished processing in {diff}') except Exception as e: logger.exception(str(e)) raise e if total_flowthrough_count: return {'status': 'OK'} return {'status': 'NO_RECORDS'}