基于aws文档,https://docs.aws.amazon.com/code-library/latest/ug/python_3_dynamodb_code_examples.html,我使用boto3客户端在dynamodb表中创建/更新数据。 dynamodb 支持字符串、数字、列表、集合和布尔值(参见下面的示例)。根据该示例,我正在设置一个带有 boolean 的 item 。但我收到一个错误,属性的预期值为字符串,但我试图将其设置为布尔真/假值。我如何构造我的请求,以便我可以通过 python 在 dynamo db 中设置布尔值?我知道该项目是一个 python 字典,我可以设置字符串值但不能设置布尔值?
db = boto3.client('dynamo')
try:
db.put_item(
Item={
"year": year,
"title": title,
"info": {"plot": plot, "rating": Decimal(str(rating))},
"rating" : 42,
"award" : {"BOOL": False}
}
)
except ClientError as err:
logger.error(err)
您正在使用低级客户端,但混合使用 JSON 类型。
阅读此内容:https://aws.amazon.com/blogs/database/exploring-amazon-dynamodb-sdk-clients/
使用低级客户端将是:
{'mybool': {'BOOL': 'False'}}
高级客户:
'mybool' : False