"""parse-bulk-assets.""" import json import uuid import boto3 from common.helpers.catalog_ingestion import log_catalog_session import config def handler(event, context): """Lambda entry point.""" # The key for the JSON master file. bucket = event.get('bucket') key = event.get('key') execution_name = event.get('execution_name') state_machine_name = event.get('state_machine_name') correlation_id = event.get('correlation_id') or str(uuid.uuid4()) logger = config.get_current_logger(correlation_id) logger.info(f'parse_bulk_assets received {bucket}/{key}.') log_catalog_session( bucket=config.SNOWFLAKE_S3_BUCKET, location=config.SNOWFLAKE_S3_LOCATION, ingest_format='bulk', file_key=key, execution_name=execution_name, state_machine_name=state_machine_name, source_id=config.CATALOG_INGESTION_SOURCE_ID ) # Read the Master JSON file s3_client = boto3.client('s3') try: file = s3_client.get_object(Bucket=bucket, Key=key) except Exception as e: error_str = f'S3 get object error: {bucket}/{key}' msg = f'{error_str}: {str(e)}' logger.error(msg) raise e file_content = file.get('Body').read() json_data = json.loads(file_content) # Construct the list of indices in the JSON file items = [] i = 0 while i < len(json_data): items.append(i) i += 1 return { 'key': key, 'bucket': bucket, 'items': items, 'execution_name': execution_name, 'state_machine_name': state_machine_name, 'correlation_id': correlation_id }