【问题标题】:dynamo db cloudformation template errordynamodb cloudformation模板错误
【发布时间】:2017-08-13 17:32:31
【问题描述】:

当我尝试加载此 cloudformation 模板以创建 dynamo db 表时出现以下错误

Property AttributeDefinitions与表的KeySchema和二级索引不一致

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "TableName": {
      "Description": "Table name to use",
      "Type": "String",
      "Default": "test-user-unique-ids"
    },
    "ReadCapacityUnits": {
      "Description": "Provisioned read throughput",
      "Type": "Number",
      "Default": "100",
      "MinValue": "1",
      "MaxValue": "10000",
      "ConstraintDescription": "must be between 1 and 10000"
    },
    "WriteCapacityUnits": {
      "Description": "Provisioned write throughput",
      "Type": "Number",
      "Default": "100",
      "MinValue": "1",
      "MaxValue": "10000",
      "ConstraintDescription": "must be between 1 and 10000"
    }
  },
  "Resources": {
    "testUserUniqueIds": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "TableName": {
          "Ref": "TableName"
        },
        "AttributeDefinitions": [
          {
            "AttributeName": "unique_id",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "guid",
            "KeyType": "HASH"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": {
            "Ref": "ReadCapacityUnits"
          },
          "WriteCapacityUnits": {
            "Ref": "WriteCapacityUnits"
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: amazon-dynamodb amazon-cloudformation


    【解决方案1】:

    属性名称定义为unique_id。但是,已经为属性guid 定义了哈希键。

    AttributeDefinitions 上定义的属性名称应在KeySchema 上使用相同的名称。它们应该是一致的。

    AttributeDefinitionsKeySchema 上都保留unique_idguid

    编辑:

    在创建 Dynamodb 表时,您可以仅包含键属性,例如分区键和排序键(如果可用)。 nosql 数据库的整个概念是每个项目,即记录可以有不同的属性。创建表时不需要定义非关键属性。 NoSQL 是无模式数据库。

    如果您在创建表时指定了任何非关键属性,您将得到验证异常。

    【讨论】:

    • 如何在表格中添加额外的列?我想为 unique_id 和 guid 和服务添加列
    • 你说没有办法做主键和对象或数组甚至副键
    • 评论不清楚。我只是添加更多信息。简单地说,创建表时只能定义关键属性。如果您有任何 GSI(全局二级索引),也可以在创建表时定义 GSI 的关键属性。任何不属于键(主表或索引)的属性都不能在创建表时定义。​​
    • 能否将键或二级索引设为数组或对象?
    • 不,DynamoDB 不支持。您不能在 Set、Map、List、Array 等文档数据类型上创建索引。
    猜你喜欢
    • 2018-08-28
    • 2016-12-03
    • 2018-06-03
    • 2016-07-11
    • 2018-06-03
    • 1970-01-01
    • 2021-11-03
    • 2013-08-07
    • 2021-05-24
    相关资源
    最近更新 更多