仅当具有所有属性值的完整实例尚不存在时才尝试将 DynamoDB put_item()


def put_items_db(data_dict):
"""
Put provided dictionary to lqtpid database
"""
try:
response = self.table.put_item(Item=data_dict, ConditionExpression='attribute_not_exists(firstName)'
 ' AND attribute_not_exists(lastName)')
http_code_response = response['ResponseMetadata']['HTTPStatusCode']
logging.debug(f'http code response for db put {http_code_response}')
except ClientError as e:
# Ignore the ConditionalCheckFailedException
if e.response['Error']['Code'] != 'ConditionalCheckFailedException':
raise

当运行代码时,它仍然上传已经存在的条目…

这个表的键是什么?我假设你放了一个和你要比较的物品有不同键值的物品。使用ConditionExpression,您只将写入的项与表中的一个项进行比较,即具有完全相同键的项。

最新更新