Leonardo Cavani Leonardo Cavani - 1 month ago 20
Node.js Question

Conditional Writes DynamoDB: Expected params.ExpressionAttributeValues[':p'] to be a structure

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:

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:

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:

"ExpressionAttributeValues":{
        ":p":true
    }

To:

"ExpressionAttributeValues":{
        ":p": {"BOOL": true}
    }
Comments