-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathget-item.js
30 lines (27 loc) · 1.06 KB
/
get-item.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
// This is an example of a simple GetCommand with the higher level DocumentClient for Amazon DynamoDB
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, GetCommand } = require("@aws-sdk/lib-dynamodb");
async function getItems() {
const client = new DynamoDBClient({ region: "us-west-2" });
const ddbDocClient = DynamoDBDocumentClient.from(client);
try {
return await ddbDocClient.send(
new GetCommand({
TableName: "RetailDatabase",
Key: {
pk: "[email protected]", // Partition Key
sk: "metadata" // Sort Key
},
// 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,
})
);
} catch (err) {
console.error(err);
}
}
getItems()
.then((data) =>
console.log("GetCommand succeeded:", JSON.stringify(data, null, 2)))
.catch((error) => console.error(JSON.stringify(error, null, 2)));