问题描述
我是DynamoDB的新手。我正在尝试使用SAM项目创建DynamoDB。我知道我只能对属性类型使用“ S”,“ N”,“ B”,但是我想像下面这样使用。
{
"TableName": "xyz","KeySchema": [
{
"AttributeName": "uid","KeyType": "HASH"
}
],"AttributeDeFinitions": [
{
"AttributeName": "uid","AttributeType": "S"
},{
"AttributeName": "email",{
"AttributeName": "postal_code",{
"AttributeName": "bookmark","AttributeType": "L" ← (I want to use List)
},{
"AttributeName": "children","AttributeType": "M" ← (I want to use Map)
}
],"ProvisionedThroughput": {
"ReadCapacityUnits": 2,"WriteCapacityUnits": 2
}
这是我的table.json,我想使用此aws命令创建表。
aws dynamodb --profile local --endpoint-url http://localhost:8000 create-table --cli-input-json file://./testdata/table.json
如何使用DynamoDB获得列表数据和地图数据?
解决方法
将项目添加到表中时,最好这样做。 DynamoDB具有灵活的架构,因此不会执行超出主键的架构。项目A可能具有attribute1,但项目B可能会忽略该属性。
创建表时,只需添加主键(分区键或分区键+排序键)即可。然后添加您的项目以及该项目所需的数据类型属性。