-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3_to_dynamodb._lambda.py
More file actions
30 lines (28 loc) · 923 Bytes
/
s3_to_dynamodb._lambda.py
File metadata and controls
30 lines (28 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import boto3
import uuid
import os
s3 = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')
def lambda_handler(event, context):
bucket = event["Records"][0]["s3"]["bucket"]["name"]
key = event["Records"][0]["s3"]["object"]["key"]
table = dynamodb.Table('heating_oil_prices')
data = s3.get_object(Bucket=bucket, Key=key)
contents = data['Body'].read().decode('utf-8')
json_content = json.loads(contents)
for item in json_content:
table.put_item(Item={
'id': str(uuid.uuid1()),
'state': item['state'],
'county': item['county'],
'supplier': item['supplier'],
'last_updated': item['last_updated'],
'price150':item['price150'],
'price300':item['price300'],
'price500':item['price500']
})
return {
'statusCode': 200,
'body': json.dumps('OK')
}