forked from aws-samples/aws-dynamodb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch-get.js
41 lines (38 loc) · 1.42 KB
/
batch-get.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
// This is an example of a simple BatchGetCommand with the higher level DocumentClient for Amazon DynamoDB
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, BatchGetCommand } = require("@aws-sdk/lib-dynamodb");
async function batchGetItems() {
const client = new DynamoDBClient({ region: "us-west-2" });
const ddbDocClient = DynamoDBDocumentClient.from(client);
try {
return await ddbDocClient.send(
new BatchGetCommand({
RequestItems: {
RetailDatabase: {
Keys: [
{
pk: "[email protected]",
sk: "metadata",
},
{
pk: "[email protected]",
sk: "metadata",
},
],
// For this use case, the data does not changed often so why not get the
// reads at half the cost? Your use case might be different and need true.
ConsistentRead: false,
},
},
//This line returns in the response how much capacity the batch get uses
ReturnConsumedCapacity: "TOTAL",
})
);
} catch (err) {
console.error(err);
}
}
batchGetItems()
.then((data) =>
console.log("BatchGetCommand succeeded:", JSON.stringify(data, null, 2)))
.catch((error) => console.error(JSON.stringify(error, null, 2)));