-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.js
More file actions
35 lines (28 loc) · 848 Bytes
/
update.js
File metadata and controls
35 lines (28 loc) · 848 Bytes
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
let AWS = require('aws-sdk');
let tableName = 'REPLACE'
let accessKeyId = 'REPLACE'
let secretAccessKey= 'REPLACE'
// id key of the item you want to update
let keyToUpdate = 'REPLACE'
AWS.config.update({
region: 'ap-southeast-1',
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey}
})
let docClient = new AWS.DynamoDB.DocumentClient()
// assign the update object from event here
let obj = {
id: keyToUpdate,
timestamp: (new Date()).toLocaleString()
}
let params = {
TableName: tableName,
Item: obj
}
// replace .put() with .update()
docClient.put(params, (err, data) => {
if (err)
return console.error("Unable to update data. Error JSON:", JSON.stringify(err, null, 2));
console.log("Update succeeded for id:", keyToUpdate)
console.log("DynamoDB response:", JSON.stringify(data, null, 2))
})