首页 > 解决方案 > 如何使用boto3将嵌套字典插入dynamodb?

问题描述

我们构建了一些嵌套格式的数据,它包含 3 个键。id 包含另一个嵌套字典的时间、id 和其他。我们不知道如何为此创建表,也不知道如何将此类数据插入到该特定表中。我们尝试使用名为 id 的 hashkey 创建一个表,但是当我们使用

dynamodb.batch_write_item(RequestItems={
    'table': [{ 'PutRequest': { 'Item':whatweget}}
    }]
})

它表明botocore.exceptions.ClientError: An error occurred (Validation Exception) when calling the BatchWriteItem operation: The prov ided key element does not match the schema 任何人都可以提供一些帮助吗?

标签: insertamazon-dynamodbboto3

解决方案


您可以在 aws 仪表板上使用 DynamoDB 控制台创建表,您可以通过 dynamodb 文档查看详细说明。

对于嵌套字典,您有多个选项,首先您可以将 id 中的值插入为xm ls 或json ns,因为 dynamodb 将接受它作为字符串,如果您想对表操作有更严格的规则,您可以创建一个id 字段和其他应该嵌套在id字段中的字段,它们不必物理存在于id中

您可以使用多种方式将数据插入到您创建的表中,最简单的是通过 aws dynamoDB 控制台手动添加它们,或者您可以使用 boto3,但您当然必须先有一个表。


推荐阅读