-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathbatch_write.py
65 lines (62 loc) · 1.93 KB
/
batch_write.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import print_function # Python 2/3 compatibility
import boto3, json, decimal
from boto3.dynamodb.conditions import Key, Attr
from botocore.exceptions import ClientError
dynamodb = boto3.resource('dynamodb', region_name='us-west-2') #replace region name with your target region
table = dynamodb.Table("RetailDatabase") #replace table name with your own
# Batch write 3 items into the table
with table.batch_writer() as batch:
batch.put_item(
Item={
'pk': '[email protected]',
'sk': 'metadata',
'username': 'vikj',
'first_name': 'Vikram',
'last_name': 'Johnson',
'name': 'Vikram Johnson',
'age': 31,
'address': {
'road': '89105 Bakken Rd',
'city': 'Greenbank',
'pcode': 98253,
'state': 'WA',
'country': 'USA'
}
}
)
batch.put_item(
Item={
'pk': '[email protected]',
'sk': 'metadata',
'username': 'joses',
'first_name': 'Jose',
'last_name': 'Schneller',
'name': 'Jose Schneller',
'age': 27,
'address': {
'road': '12341 Fish Rd',
'city': 'Freeland',
'pcode': 98249,
'state': 'WA',
'country': 'USA'
}
}
)
batch.put_item(
Item={
'pk': '[email protected]',
'sk': 'metadata',
'username': 'helgar',
'first_name': 'Helga',
'last_name': 'Ramirez',
'name': 'Helga Ramirez',
'age': 48,
'address': {
'road': '45678 Deer Lake Rd',
'city': 'Clinton',
'pcode': 98236,
'state': 'WA',
'country': 'USA'
}
}
)