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?

George B
  • 2,592
  • 3
  • 22
  • 27
  • This question solved it for me: http://stackoverflow.com/questions/30586608/cant-update-item-in-dynamodb – George B Jan 09 '16 at 05:13

2 Answers2

13

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'})
user254873
  • 166
  • 1
  • 5
  • Please check this [URL](http://stackoverflow.com/help) it will be useful to raise your content quality up – Willie Cheng May 31 '16 at 09:37
  • 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! – FreyGeospatial Aug 11 '22 at 20:32
  • 1
    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 – Mike B Nov 01 '22 at 16:48
-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.

Chandra Sekhar K
  • 317
  • 7
  • 18