gpt4 book ai didi

python - DynamoDB : Create Table with keytype for nested json using Boto3

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:14 26 4
gpt4 key购买 nike

我正在尝试使用 MongoDB 中的数据格式在 DynamoDB 中创建一个新表。我知道如何创建基本表和更新数据,但是,对于嵌套的 JSON 主体,我无法创建 KeySchema,因为我是新手。

我的 JSON 示例:

{
'Name':"fresco"
'Tags':{
'Genre':'Jazz'
'Albums':['aa','bb''cc']}
'Year:'2009
}

我正在使用 boto3,并且我知道如何连接 AWS,我只需要有关此 JSON 主体的 key 架构的一些帮助。另外,我读过Map attribute来自 AWS 文档,但没有实现。

我的代码:

import boto3
dynamodb =boto3.resource('dynamodb')
table = dynamodb.create_table(
TableName = 'newTable'
KeySchema = [
{
'AttributeName': 'Name',
'KeyType': 'Hash'
},
{
'AttributeName': 'Tags',
'KeyType': 'Hash'
},
{
'AttributeName': 'Year',
'KeyType': 'Hash'
}

],

AttributeDefinitions=[
{
'AttributeName': 'Name',
'AttributeType': 'S'
},
{
'AttributeName': 'Tags',
'AttributeType': #dont know what to put in here.
},
{
'AttributeName': 'Year',
'AttributeType': 'N'
},


],

ProvisionedThroughput ={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5

}

)

最佳答案

在 DynamoDB 中,您只能拥有一个分区键或一个分区键 + 一个排序键。而且您对 key 的长度也有限制 - 因此标签可能不是最合适的。最好阅读developer docs .

关于python - DynamoDB : Create Table with keytype for nested json using Boto3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47129690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com