"""Lambda gda_knowledge_graph function module.""" from lambdacommon.common_config import logger from lambdacommon.common_config import SENTRY_DSN from requests import RequestException import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from sentry_sdk import capture_exception import config from src import constants from src import graphql_gateway sentry_sdk.init( dsn=SENTRY_DSN, environment=config.ENVIRONMENT, integrations=[AwsLambdaIntegration(timeout_warning=True)] ) class RetryException(Exception): """Retry Exception. It tells the state machine to retry lambda execution. """ pass class FatalException(Exception): """Fatal exception. It tells the state machine to abort the lambda execution. """ pass def handler(event: dict, context: dict) -> dict: """Lambda entry point.""" try: correlation_id = event.get('correlation_id') logger.info(f'CorrelationID: {correlation_id}') logger.info( 'Querying label participants and social stats...') global_participant_data = graphql_gateway.get_global_participant_data(event) logger.info( f'Global participant data returned from the knowlegde graph: {global_participant_data}') return global_participant_data except RequestException as e: logger.exception(constants.ERROR_REQUEST_EXCEPTION) capture_exception(e) raise RetryException(str(e)) except Exception as e: logger.exception(constants.ERROR_LAMBDA_FATAL) capture_exception(e) raise FatalException(str(e))