python-仅当dynamodb项已经存在时才更新它
我正在尝试更新 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}