Question:
I’m trying to update my DynamoDB table using a conditional write, after read the official doc (https://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.03.html#GettingStarted.NodeJs.03.05) I’m getting an error, I think this is a Syntax error, but I’m not sure, this is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
dynamodb.updateItem({ dynamodb.updateItem({ "TableName": "MyFavTable", "Key":{ "MyFavKey": { "S": "MyFavKey" } }, "UpdateExpression": "set MyLovelyBool=false", "ConditionExpression": "MyLovelyBool == :p", "ExpressionAttributeValues":{ ":p":true } }, function(err, data) { if (err) { console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2)); } else { console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2)); } }); |
This run ‘fine’ by I get this error:
1 2 3 4 5 6 |
Unable to update item. Error JSON: { "message": "Expected params.ExpressionAttributeValues[':p'] to be a structure", "code": "InvalidParameterType", "time": "2016-10-22T14:48:42.961Z" } |
I check if the json is valid and I was reading about ExpressionAttributeValues here (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames) but I don’t get info to resolve my problem.
Answer:
Per the documentation, change this:
1 2 3 4 |
"ExpressionAttributeValues":{ ":p":true } |
To:
1 2 3 4 |
"ExpressionAttributeValues":{ ":p": {"BOOL": true} } |