-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateItem.js
49 lines (44 loc) · 1.36 KB
/
updateItem.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
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
ABOUT THIS NODE.JS EXAMPLE: This example works with the AWS SDK for JavaScript (v3),
which is available at https://github.com/aws/aws-sdk-js-v3.
Purpose:
updateItem.js demonstrates how to use the Amazon DynamoDB document client to create or update an item in an Amazon DynamoDB table.
Inputs (replace in code):
- TABLE_NAME
- MOVIE_NAME
- MOVIE_YEAR
- MOVIE_PLOT
- MOVIE_RANK
Running the code:
node updateItem.js
*/
// snippet-start:[dynamodb.JavaScript.movies.updateItemV3]
import { UpdateCommand } from "@aws-sdk/lib-dynamodb";
import { ddbDocClient } from "../libs/ddbDocClient.js";
export const updateItem = async () => {
// Set the parameters.
const params = {
TableName: "TABLE_NAME",
Key: {
title: "MOVIE_NAME",
year: "MOVIE_YEAR",
},
ProjectionExpression: "#r",
ExpressionAttributeNames: { "#r": "rank" },
UpdateExpression: "set info.plot = :p, info.#r = :r",
ExpressionAttributeValues: {
":p": "MOVIE_PLOT",
":r": "MOVIE_RANK",
},
};
try {
const data = await ddbDocClient.send(new UpdateCommand(params));
console.log("Success - item added or updated", data);
return data;
} catch (err) {
console.log("Error", err);
}
};
updateItem();
// snippet-end:[dynamodb.JavaScript.movies.updateItemV3]