Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- import csv
- def lambda_handler(event, context):
- region='us-east-2'
- try:
- print('s3')
- s3 = boto3.client('s3')
- print('dyndb')
- dyndb = boto3.client('dynamodb', region_name=region)
- object_response = s3.get_object(Bucket='cc-class', Key='Cost_of_living_index.csv')
- # print(response['Body'].read())
- city_row = object_response['Body'].read().decode('utf-8').split('\r\n')
- csv_reader = csv.reader(city_row, delimiter=',', quotechar='"')
- header = []
- firstrecord = True
- for row in csv_reader:
- if(firstrecord):
- firstrecord = False
- continue
- print(row)
- put_response = dyndb.put_item(
- TableName='CostOfLiving',
- Item={
- "Rank" :
- { "N" : row[0]},
- "City" :
- { "S" : row[1]},
- "Cost of Living Index" :
- { "N" : row[2]},
- "Rent Index" :
- { "N" : row[3]},
- "Cost of Living Plus Rent Index" :
- { "N" : row[4]},
- "Groceries Index" :
- { "N" : row[5]},
- "Restaurant Price Index" :
- { "N" : row[6]},
- "Local Purchasing Power Index" :
- { "N" : row[7]}
- }
- )
- except Exception as e:
- print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement