Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 439
BigBugCreator Avatar asked Oct 22 '16 15:10

BigBugCreator


People also ask

What is expressionattributevalues in DynamoDB?

Expression attribute values in Amazon DynamoDB are substitutes for the actual values that you want to compare—values that you might not know until runtime. An expression attribute value must begin with a colon ( : ) and be followed by one or more alphanumeric characters.

Does Amazon DynamoDB support conditional operations?

Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.


1 Answers

Per the documentation, change this:

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

To:

"ExpressionAttributeValues":{
        ":p": {"BOOL": true}
    }
like image 145
Mark B Avatar answered Sep 30 '22 09:09

Mark B