如何通过 aws-cli 创建具有嵌套属性定义的 dynamodb 架构?

Dud*_*ode 7 node.js amazon-dynamodb aws-cli aws-sdk

我一直在使用该命令aws dynamodb create-table --cli-input-json创建本地 dynamodb 表以在本地机器上进行测试。

我可以创建简单的表格,但无法创建更复杂的现实世界表格。我查看了AWS文档,它缺少嵌套AttributeDefinitions的解释,或者我找不到它。以下是一个简单的示例(用于通过 AWS CLI 创建):

{
  "TableName": "fruitsTable",
  "KeySchema": [
    {
      "AttributeName": "fruitId",
      "KeyType": "HASH"
    }
  ],
  "AttributeDefinitions": [
    {
      "AttributeName": "fruitId",
      "AttributeType": "S"
    }
  ],
  "ProvisionedThroughput": {
    "ReadCapacityUnits": 5,
    "WriteCapacityUnits": 5
  }
}
Run Code Online (Sandbox Code Playgroud)

效果很好。aws dynamodb create-table --cli-input-json file:///Users/you/subfile/server/config/tables/fruits.json --endpoint-url http://localhost:8000

不过,我想看一个创建更复杂的对象的示例。什么模式适用于此?

{
  "ComplexFruit" : [
    {
      "complexFruitId": "redbanana-fromGroceryStore"
      "name" : "redBanana", 
      "notes": "this one is red",
      "count" : {
        "ripe" : 5,
        "total": 10
       },
      "stores" : [ 
          {"storeName" : "Exito"}
       ]
     }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我对如何创建嵌套而感到困惑,AttributeDefinition而无需大量猜测或挖掘代码(如果 dynamodb 是开源的?)。有人知道吗?这显然也是一个人为的示例,但它将演示如何创建嵌套模式。

Bri*_*ant 5

您只需指定AttributeDefinitions将成为表主键或索引键一部分的属性。Dynamo 大部分是无模式的(除了关键定义之外)。它不关心您想要存储的任何其他属性 - 无需对任何内容进行建模。