【发布时间】:2021-02-09 21:23:21
【问题描述】:
我是 DynamoDB 的新手。我正在尝试使用 SAM 项目创建 DynamoDB。我知道我只能对 AttributeType 使用“S”、“N”、“B”,但我想像下面这样使用。
{
"TableName": "xyz",
"KeySchema": [
{
"AttributeName": "uid",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "uid",
"AttributeType": "S"
},
{
"AttributeName": "email",
"AttributeType": "S"
},
{
"AttributeName": "postal_code",
"AttributeType": "S"
},
{
"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 获取列表数据和地图数据?
【问题讨论】:
-
只知道您不必在表定义中的项目上添加您计划拥有的所有属性。每个项目都可以有自己的一组属性。项目唯一必须拥有的是构成主键的那些。
-
感谢您的回答。你的意思是我只是在 JSON 中定义主键,然后将一个包含我想要从我的 lambda 代码放入 DynamoDB 的所有数据的对象?
-
是的。 DynamoDB 不会强制使用超出主键的架构。这意味着一个项目可能具有属性 A,但另一个项目甚至没有。这种方式非常灵活。
-
我可以将所有数据放入 DynamoDB。谢谢!
标签: aws-lambda amazon-dynamodb dynamo-local