返回

python-仅当dynamodb项已经存在时才更新它

发布时间:2022-08-12 09:52:06 234
# node.js

我正在尝试更新 dynamodb 上的项目,但是如果它不存在,我不希望它创建一个新项目。我试过了:

dynamodb = boto3.client('dynamodb')

element = 'test'

dynamodb.update_item(

               TableName='myTable',

               Key={

                   'serial':{

                       'S':element

                   }

               },

               AttributeUpdates={

                   'total':{

                       'Value':{

                           'N':'0'

                       },

                       'Action':'PUT'

                   }

               },

              UpdateExpression ='serial= :serial',

              ExpressionAttributeNames={

               ':serial':'VM1'

              }

           ) 

但我得到这个错误:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters: {UpdateExpression}

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像