Dynamodb Update Error Invalid Updateexpression: an Expression Attribute Value Used in Expression Is Not Defined

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?

2

1 Answer

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'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.