"""Main Handler.""" import json from bulk_metadata_ingester_common.constants.data_headers import ( FIELD_JOIN_CONST) from bulk_metadata_ingester_common.utils.jitter import jitter from bulk_metadata_ingester_common.utils.logging import get_current_logger import config from config import graphql_gateway from lambdacommon.aws import s3 def handler(event, context): """Lambda Entrypoint.""" key = event.get('key') bucket = event.get('bucket') item_index = event.get('item_index') correlation_id = event.get('correlation_id') logger = get_current_logger( config.ENVIRONMENT, config.LAMBDA_NAME, logging_level=config.LOGGING_LEVEL, correlation_id=correlation_id) # Jitter calls - Sleep for randomness jitter(logger) graphql_gateway.set_headers( { 'Orchard-User-Id': config.OA_USER, 'Correlation-Id': correlation_id } ) # Log lambda begins message logger.info(f'enrich_data received: {event}') # Grab file object passed in via key file = s3.client.get_object(Bucket=bucket, Key=key) # Get the JSON content from the object file_content = file.get('Body').read() # Convert the JSON into a dict data = json.loads(file_content) # Grab an item from the list via passed item_index release_track_list = data[item_index] # Get project_code and product_code from index project_code, product_code = item_index.split(FIELD_JOIN_CONST) enrich_data(release_track_list, correlation_id) return event def enrich_data(item, correlation_id): """Process the release. Args: item (object): The release list. Contains a list of dicts (tabular). correlation_id (str): Correlation_id for logging. Returns: object: Response. """ logger = config.get_current_logger(correlation_id) # Log lambda begins message logger.info(f'enrich_data processed NOTHING: {item}') return item