PropertyDefinition不一致

问题描述 投票:42回答:1

我有以下模板,我在cloudformation UI中使用它来创建dynamoDB表。我想创建一个表,其中PrimaryKey为ID,sortKey为Value

{
  "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"
    }
  }
}

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

amazon-web-services amazon-dynamodb amazon-cloudformation
1个回答
75
投票

问题是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"
    }
   }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.