【问题标题】:Dynamodb Update Item Expression with python boto3Dynamodb 使用 python boto3 更新项目表达式
【发布时间】:2016-04-13 21:29:19
【问题描述】:
我有一个字符串字段“title”。我正在尝试使用更新表达式更新它
persontable.update_item(Key={'person_id':person_id}, UpdateExpression="SET title = UPDATED")
我明白了
An error occurred (ValidationException) when calling the UpdateItem operation: The provided expression refers to an attribute that does not exist in the item
我可以在 AWS 控制台中看到该人的属性“title”。什么给了?
【问题讨论】:
标签:
python-2.7
amazon-web-services
amazon-dynamodb
boto
【解决方案1】:
不要将值直接插入表达式。而是使用 ExpressionAttributeValues -- 参见 boto3 guide
persontable.update_item(Key={'person_id':person_id},
UpdateExpression="SET title = :updated",
ExpressionAttributeValues={':updated': 'UPDATED'})
【解决方案2】:
更新前检查项目是否已正确创建。
当表未处于“ACTIVE”状态时,如果您尝试 put_item - 它将不会被创建,并且当您尝试更新未创建的同一项目时,下一个。会出现这个错误。
当 state 处于“ACTIVE”状态时执行 put_item,然后正确更新 item。您不会收到此错误。