"""Lambda begin_execution function module.""" from typing import Any from uuid import UUID from common.connectors import ows_product_staging_obo from common.connectors.graphql import obo_graphql as graphql from common.schemas.ingestion import BulkEvent from lambdacommon.common_config import logger import config def handle(event: BulkEvent) -> BulkEvent: """ Lambda entry point. Args: event_data: Lambda event payload (should look like event.shadow.json) context: Lambda context. Returns: The input event_data unchanged. """ if not event.execution_arn: logger.error( "No execution_arn found in event.", ) return event impersonated_identity_uuid = event.identity_uuid ows_product_staging_obo.upsert_ingestion_execution( bulk_session_ingestion_id=UUID(event.bulk_session_ingestion_id), execution_arn=event.execution_arn, impersonated_identity_uuid=impersonated_identity_uuid, ) graphql.init_graphql_client( environment=config.ENVIRONMENT, service_name=config.M2M_APPLICATION_NAME, graphql_service_name=config.GRAPHQL_SERVICE_NAME, identity_id=impersonated_identity_uuid, profile_id=config.PROFILE_ID, profile_type=config.PROFILE_TYPE, headers={ "Correlation-Id": event.correlation_id, "Orchard-Roles": config.ROLE, }, ) if event.send_notifications: graphql.notify_ingestion_started( bulk_session_ingestion_id=event.bulk_session_ingestion_id, execution_arn=event.execution_arn, ) return event def handler(event_data: dict[str, Any], context: Any) -> dict[str, Any]: """ Lambda handler function. Args: event_data: Lambda event payload (should look like event.shadow.json) context: Lambda context. Returns: The input event_data unchanged. """ event = BulkEvent(**event_data) return handle(event).model_dump()