-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathupdate-item.js
34 lines (30 loc) · 1.12 KB
/
update-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
31
32
33
34
/* This is an example of an UpdateCommand using the higher level DocumentClient
for Amazon DynamoDB. It updates one attribute on the item, but it could easily
do more if needed. */
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, UpdateCommand } = require("@aws-sdk/lib-dynamodb");
async function updateItem() {
const client = new DynamoDBClient({ region: "us-west-2" });
const ddbDocClient = DynamoDBDocumentClient.from(client);
return await ddbDocClient.send(
new UpdateCommand({
TableName: "RetailDatabase",
Key: {
pk: "[email protected]", // Partition key
sk: "metadata", // Sort key
},
ExpressionAttributeNames: {
"#n": "name",
},
UpdateExpression: "set #n = :nm",
ExpressionAttributeValues: {
":nm": "Big Jim Bob",
},
ReturnValues: "ALL_NEW",
})
);
}
updateItem()
.then((data) =>
console.log("UpdateCommand succeeded:", JSON.stringify(data, null, 2)))
.catch((error) => console.error(JSON.stringify(error, null, 2)));