Dynamodb Update Item Expression with python boto3

心已入冬 提交于 2019-12-24 17:28:25

问题


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:


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'})



回答2:


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.



来源:https://stackoverflow.com/questions/34689912/dynamodb-update-item-expression-with-python-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!