"""Lambda ledger_accounting_run_balance function module.""" from datetime import datetime import sentry_sdk from sentry_sdk import capture_exception from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from snowflake_connector.etl_connector import SnowflakeSQLExecutor import config from ledger_accounting_run_balance.processor import LedgerAccountingRunBalanceProcessor if config.SENTRY_DSN: sentry_sdk.init( dsn=config.SENTRY_DSN, environment=config.ENVIRONMENT, integrations=[AwsLambdaIntegration(timeout_warning=True)] ) def handler(event, context): """Lambda entry point.""" try: with SnowflakeSQLExecutor(config.SNOWFLAKE_CONFIG) as sf_executor: processor = LedgerAccountingRunBalanceProcessor(event, sf_executor) start_time = datetime.now() processor.process() end_time = datetime.now() diff = end_time - start_time print(f'Finished processing in {diff}') except Exception as e: capture_exception(e) raise e return {'status': 'OK'}