如何通过 aws-cli 创建具有嵌套属性定义的 dynamodb 模式? [英] How do I create a dynamodb schema with nested attribute definitions via aws-cli?

查看:38
本文介绍了如何通过 aws-cli 创建具有嵌套属性定义的 dynamodb 模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been using the command aws dynamodb create-table --cli-input-json to create local dynamodb tables for testing on my local box.

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

I can create simple tables but I cannot create more complex, real world tables. I looked through the AWS documentation and it's missing the explanation for nested AttributeDefinitions, or I could not find it. Here's a simple example that works (for creation through the AWS CLI):

{
  "TableName": "fruitsTable",
  "KeySchema": [
    {
      "AttributeName": "fruitId",
      "KeyType": "HASH"
    }
  ],
  "AttributeDefinitions": [
    {
      "AttributeName": "fruitId",
      "AttributeType": "S"
    }
  ],
  "ProvisionedThroughput": {
    "ReadCapacityUnits": 5,
    "WriteCapacityUnits": 5
  }
}

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

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

However I would like to see an example of creating an object that is more complex. What schema would work for this?

{
  "ComplexFruit" : [
    {
      "complexFruitId": "redbanana-fromGroceryStore"
      "name" : "redBanana", 
      "notes": "this one is red",
      "count" : {
        "ripe" : 5,
        "total": 10
       },
      "stores" : [ 
          {"storeName" : "Exito"}
       ]
     }
   ]
}

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

I am stumped on how I can create a nested AttributeDefinition without a ton of guessing or digging through the code (if dynamodb is open source?). Does anyone know? Also this obviously a contrived example but it would demonstrate how to create nested schemas.

推荐答案

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

You only need to specify AttributeDefinitions for attributes that will be part of the table's primary key or part of an index's key. Dynamo is mostly schemaless (other than the key definitons). It doesn't care about any of the other attributes you want to store - there is no need to model anything.

这篇关于如何通过 aws-cli 创建具有嵌套属性定义的 dynamodb 模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆