PropertyDefinition不一致

Em *_* Ae 66 amazon-web-services aws-cloudformation amazon-dynamodb

我有以下模板,我在cloudformation UI中使用它来创建dynamoDB表.我想创建一个表,其中PrimaryKeyID,sortKeyValue

{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "DB Description",

  "Resources" : {
    "TableName" : {
      "Type" : "AWS::DynamoDB::Table",
      "Properties" : {
        "AttributeDefinitions": [ { 
          "AttributeName" : "ID",
          "AttributeType" : "S"
        }, { 
          "AttributeName" : "Value",
          "AttributeType" : "S"
        } ],
        "KeySchema": [
          { 
            "AttributeName": "ID", 
            "KeyType": "HASH"
          }
        ]                
      },
      "TableName": "TableName"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在CF UI上,我单击新堆栈,template从本地计算机指向该文件,为堆栈命名并单击下一步.一段时间后,我收到错误,指出Property AttributeDefinitions与表的KeySchema和二级索引不一致

jen*_*ter 114

问题是Resources.Properties.AttributeDefinitions密钥必须定义用于索引或键的列.换句话说,键Resources.Properties.AttributeDefinitions必须匹配中定义的相同键Resources.Properties.KeySchema.

AWS文档:

AttributeDefinitions:AttributeName和AttributeType对象的列表,用于描述表和索引的键架构.

所以生成的模板看起来像这样:

{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "DB Description",

  "Resources" : {
    "TableName" : {
    "Type" : "AWS::DynamoDB::Table",
    "Properties" : {
      "AttributeDefinitions": [ { 
        "AttributeName" : "ID",
        "AttributeType" : "S"
      } ],
      "ProvisionedThroughput":{
        "ReadCapacityUnits" : 1,
        "WriteCapacityUnits" : 1
      },
      "KeySchema": [
        { 
          "AttributeName": "ID", 
          "KeyType": "HASH"
        }
       ] ,               
      "TableName": "table5"
    }
   }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • /sf/ask/1792429481/经过研究,您无需在创建表时定义所有列,只需索引,然后就可以了插入新行时"随时随地"添加属性 (24认同)
  • 如果我们从AttributeDefinitions中删除'value'属性,我们如何将'Value'列添加到表中? (3认同)