-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdynamodb_loader.py
More file actions
50 lines (48 loc) · 1.71 KB
/
dynamodb_loader.py
File metadata and controls
50 lines (48 loc) · 1.71 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import boto3
import json
#Loader file for DynamoDB
#Reference:
#https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.02.html
"""
Sample JSON
{
"descr": "Meghan is a retired cardiothoracic surgeon, so if you ever want to know anything about hearts(physical or otherwise), she is the person to go to! She also loves music and reading.",
"home": "Tranquility Retirement",
"interests": [
"reading",
"music"
],
"name": "Meghan",
"profile": "https://caring-companions.s3.amazonaws.com/profile_pictures/citizens/seniors-citizen-age-@1X.jpg",
"timeslots": [
"2-4",
"4-6"
],
"citizenid": "c9f8c668-5b8b-4801-bfcd-b4b480657981"
}
"""
dynamodb = boto3.resource('dynamodb', region_name='us-east-1', endpoint_url="https://dynamodb.us-east-1.amazonaws.com")
table = dynamodb.Table('citizens')
with open('D:\Python-Hack-Projects\caring-companion-v2\citizendata.json') as json_file:
citizens = json.load(json_file)
for citizen in citizens:
citizenid = citizen['citizenid']
desc = citizen['descr']
name = citizen['name']
home = citizen['home']
interests = citizen['interests']
profile = citizen['profile']
timeslots = citizen['timeslots']
response = table.put_item(
Item = {
'citizenid':citizenid,
'desc':desc,
'name':name,
'home':home,
'interests':interests,
'profile':profile,
'timeslots':timeslots,
}
)
print("Put item succeeded")
print(json.dumps(response, indent=4))