1 Answer
- Newest
- Most votes
- Most comments
1
I tested this in my own account and it works with no issue, returning the NEW_IMAGE in the response to ensure the update was successful:
const AWS = require('aws-sdk');
const dynamoDb = new AWS.DynamoDB({region: 'eu-west-1'});
var hID = "24cf6015-780e-408d-b0e1-935ae2c7199d";
var params = {
TableName: "cust1",
Key: {
pk: { "S": "123" },
sk: { "S": "abc" }
},
UpdateExpression: "SET #hp.#id.#a = :a",
ExpressionAttributeValues: { ":a": { "N": "0" } },
ExpressionAttributeNames: { "#hp": "hedge_positions", "#id": hID, "#a": "active" },
ReturnValues: "ALL_NEW"
};
dynamoDb.updateItem(params)
.promise()
.then(res=>console.log(JSON.stringify(res)))
.catch(err=>console.log(err));
Item before:
{
"pk": "123",
"sk": "abc",
"active": 1,
"delta": -0.9371997798455771,
"dte": 0.01893752246685426,
"hedge_positions": {
"151e9c9f-aa5d-4f5d-9826-74011da03137": {
"active": 1
},
"1bed59c9-6f73-48ae-8b65-62fd1f10ddad": {
"active": 1
},
"24cf6015-780e-408d-b0e1-935ae2c7199d": {
"active": 1
}
}
}
Item After:
{
"pk": "123",
"sk": "abc",
"active": 1,
"delta": -0.9371997798455771,
"dte": 0.01893752246685426,
"hedge_positions": {
"151e9c9f-aa5d-4f5d-9826-74011da03137": {
"active": 1
},
"1bed59c9-6f73-48ae-8b65-62fd1f10ddad": {
"active": 1
},
"24cf6015-780e-408d-b0e1-935ae2c7199d": {
"active": 0
}
}
}
Relevant content
- asked 5 years ago
- asked 2 years ago
- asked 7 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago