擅长:python、mysql、java
<p>DynamoDB以一种非常特殊的方式处理dat类型,您可以找到更多信息<a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html" rel="nofollow noreferrer">here</a>和<a href="https://boto3.amazonaws.com/v1/documentation/api/latest/_modules/boto3/dynamodb/types.html" rel="nofollow noreferrer">here</a></p>
<p>在您的例子中,问题在于update命令的值<code>"true"</code>。使用类型可能很棘手,<code>boto3</code>提供了一个<code>TypeSerializer</code>和<code>TypeDeserializer</code>可用于为您处理转换:</p>
<pre class="lang-py prettyprint-override"><code>import boto3
from boto3.dynamodb.types import TypeSerializer
serializer = TypeSerializer()
my_single_value = "processed"
print(serializer.serialize(my_single_value))
# {'S': 'processed'}
my_dict_object = {
"processed": "true"
}
print({k: serializer.serialize(v) for k, v in my_dict_object.items()})
# {'processed': {'S': 'true'}}
</code></pre>