26

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
  • Are you sure that event is defined? Add a console.log(JSON.stringify(params)) just before you call docClient.update(..) Commented Oct 4, 2016 at 8:01
  • I think notionquest's answer below solves the issue. Commented Oct 4, 2016 at 8:11

1 Answer 1

48

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.