8

I have a string field, "title". I am trying to update it with the update expression with

persontable.update_item(Key={'person_id':person_id}, UpdateExpression="SET title = UPDATED")

and I get

An error occurred (ValidationException) when calling the UpdateItem operation: The provided expression refers to an attribute that does not exist in the item

I can see the attribute "title" for that person in the AWS console. What gives?

1

2 Answers 2

14

Don't plug the value into the expression directly. Rather use ExpressionAttributeValues -- see boto3 guide

persontable.update_item(Key={'person_id':person_id},
                        UpdateExpression="SET title = :updated",                   
                        ExpressionAttributeValues={':updated': 'UPDATED'})
Sign up to request clarification or add additional context in comments.

3 Comments

Please check this URL it will be useful to raise your content quality up
This answer solved my problem, where I was previously attempting to plug the value into the expression directly and my code errored out. Thank you!
why does AWS make this so complicated? i.e., why do we write out an arbitrary string that AWS CLI parses? seems like an overly complicated approach
-1

Check whether item has created properly before updating.

When the Table is not in "ACTIVE" state, if you try to put_item - it will not be created and next when when you try to update the same item which is not created. This error will occur.

Execute the put_item when the state is in "ACTIVE" state and then update item properly. You will not get this error.

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.