import json import os import csv import boto3 import pandas as pd def lambda_handler(event, context): # Uploads the mvWarMainProp data to DynamoDB s3client = boto3.client('s3') s3 = boto3.resource('s3') print('Event:' + str(event)) print('Event-Records:' + str(event['Records'])) print('Event-Records-S3:'+ str(event['Records'][0]['s3'])) print('Event-Records-S3-bucket-name:'+ str(event['Records'][0]['s3']['bucket']['name'])) input_bucket = event['Records'][0]['s3']['bucket']['name'] input_key = event['Records'][0]['s3']['object']['key'] os.chdir('/tmp/') input_file_list = input_key.split('/') input_file = input_file_list[1] input_file_path = '/tmp/' + str(input_file) print("File:" + str(input_file)) print("File Path" + '/tmp/' + str(input_file)) #response = s3client.get_object(Bucket=input_bucket, Key=input_key) s3client.download_file(input_bucket, input_key, input_file_path) os.chdir('/tmp/') dynamo = boto3.resource('dynamodb') table = dynamo.Table(os.environ['DynamoDbTable']) well_activity = pd.read_csv(input_file, delimiter = ',') for index, row in well_activity.iterrows(): print ('SN_WAR: ' + str(row['SN_WAR'])) response = table.put_item( Item={'SN_WAR':str(row['SN_WAR']), 'TOTAL_DEPTH_DATE':str(row['TOTAL_DEPTH_DATE']), 'WELL_ACTV_START_DT':str(row['WELL_ACTV_START_DT']), 'DRILLING_MD':str(row['DRILLING_MD']) }) return { 'Message': 'success' }