Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import boto3
  2. import csv
  3. def lambda_handler(event, context):
  4. region='us-east-2'
  5. try:
  6. print('s3')
  7. s3 = boto3.client('s3')
  8. print('dyndb')
  9. dyndb = boto3.client('dynamodb', region_name=region)
  10.  
  11. object_response = s3.get_object(Bucket='cc-class', Key='Cost_of_living_index.csv')
  12. # print(response['Body'].read())
  13. city_row = object_response['Body'].read().decode('utf-8').split('\r\n')
  14.  
  15. csv_reader = csv.reader(city_row, delimiter=',', quotechar='"')
  16.  
  17. header = []
  18.  
  19. firstrecord = True
  20. for row in csv_reader:
  21. if(firstrecord):
  22. firstrecord = False
  23. continue
  24.  
  25. print(row)
  26.  
  27. put_response = dyndb.put_item(
  28. TableName='CostOfLiving',
  29. Item={
  30. "Rank" :
  31. { "N" : row[0]},
  32. "City" :
  33. { "S" : row[1]},
  34. "Cost of Living Index" :
  35. { "N" : row[2]},
  36. "Rent Index" :
  37. { "N" : row[3]},
  38. "Cost of Living Plus Rent Index" :
  39. { "N" : row[4]},
  40. "Groceries Index" :
  41. { "N" : row[5]},
  42. "Restaurant Price Index" :
  43. { "N" : row[6]},
  44. "Local Purchasing Power Index" :
  45. { "N" : row[7]}
  46. }
  47. )
  48.  
  49. except Exception as e:
  50. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement