Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB update error Invalid UpdateExpression: An expression attribute value used in expression is not defined

I am trying to perform an update on DynamoDB table.

The code is (Node.js):

    let params = {
        TableName: Organizations.Table,
        Key: {
            'ID': event.ID
        },
        UpdateExpression: 'SET #OrgName = :org, #Description = :desc',
        ExpressionAttributeNames: {
            '#OrgName': 'OrgName',
            '#Description': 'Description'
        },
        ExpressionAtributeValues: {
            ':org': event.OrgName,
            ':desc': event.Description
        },
        ReturnValues: 'UPDATED_NEW'
    };
    this.docClient.update(params, (err, data) => {
        if (err) {
            return cb(err);
        }
        return cb(null, data);
    });

The event object has all the properties needed.

After executing I get an error:

Invalid UpdateExpression: An expression attribute value used in expression is not defined; attribute value: :desc

I just followed the examples from DynamoDB docs. When I change the order of set values, e.g. to SET #Description = :desc, #OrgName = :org the error I get will be about attribute value :org. I also tried to specify expression attribute values explicitly, didn't help.

I can't get what is wrong.

Can someone help me?

like image 363
Vasiliy Solovey Avatar asked Oct 03 '16 13:10

Vasiliy Solovey


People also ask

How to update a value in DynamoDB?

To update an existing item in an Amazon DynamoDB table, you use the UpdateItem operation. You must provide the key of the item that you want to update. You must also provide an update expression, indicating the attributes that you want to modify and the values that you want to assign to them.

What is expression attribute names in DynamoDB?

An expression attribute name is a placeholder that you use in an Amazon DynamoDB expression as an alternative to an actual attribute name. An expression attribute name must begin with a pound sign ( # ), and be followed by one or more alphanumeric characters.

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.

What is the use of add new attribute method in DynamoDB?

ADD - Causes DynamoDB to create an item with the supplied primary key and number (or set of numbers) for the attribute value. The only data types allowed are Number and Number Set.


1 Answers

There is a spelling mistake in ExpressionAtributeValues (i.e. 't' missing) which is causing the problem.

Please try the below. It should work.

UpdateExpression : "SET #OrgName = :org, #Description = :desc",
    ExpressionAttributeNames: {
        '#OrgName' : 'OrgName',
        '#Description' : 'Description'
    },
    ExpressionAttributeValues: {':org' : 'new org value', 
        ':desc' : 'new desc value'          
    },
    ReturnValues: 'UPDATED_NEW'
like image 137
notionquest Avatar answered Sep 20 '22 10:09

notionquest