-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathbatch-write.js
68 lines (65 loc) · 2.24 KB
/
batch-write.js
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
66
67
68
// This is an example of a simple BatchWriteCommand with the higher level DocumentClient for Amazon DynamoDB
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, BatchWriteCommand } = require("@aws-sdk/lib-dynamodb");
async function batchWriteItems() {
const client = new DynamoDBClient({ region: "us-west-2" });
const ddbDocClient = DynamoDBDocumentClient.from(client);
try {
return await ddbDocClient.send(
new BatchWriteCommand({
RequestItems: {
RetailDatabase: [
{
PutRequest: {
Item: {
pk: "[email protected]",
sk: "metadata",
username: "vikj",
first_name: "Billy",
last_name: "Johnson",
name: "Billy Johnson",
age: 31,
address: {
road: "89105 Bakken Rd",
city: "Greenbank",
pcode: 98253,
state: "WA",
country: "USA",
},
},
},
},
{
PutRequest: {
Item: {
pk: "[email protected]",
sk: "metadata",
username: "joses",
first_name: "Juan",
last_name: "Schneller",
name: "Juan Schneller",
age: 27,
address: {
road: "12341 Fish Rd",
city: "Freeland",
pcode: 98249,
state: "WA",
country: "USA",
},
},
},
},
],
},
//This line returns in the response how much capacity the batch get uses
ReturnConsumedCapacity: "TOTAL",
})
);
} catch (err) {
console.error(err);
}
}
batchWriteItems()
.then((data) =>
console.log("BatchWriteCommand succeeded:", JSON.stringify(data, null, 2)))
.catch((error) => console.error(JSON.stringify(error, null, 2)));