首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PropertyDefinition不一致

PropertyDefinition不一致
EN

Stack Overflow用户
提问于 2017-01-28 22:51:40
回答 2查看 20.9K关注 0票数 74

我在cloudformation中使用下面的模板来创建dynamoDB表。我想要创建一个以PrimaryKey作为ID,sortKey作为值的表

代码语言:javascript
运行
复制
{
  "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上,我单击新堆栈,指向本地计算机上的template文件,给出堆栈名称,然后单击next。过了一段时间,我得到一个错误,即属性AttributeDefinitions与表的KeySchema和辅助索引不一致。

EN

回答 2

Stack Overflow用户

发布于 2020-02-12 18:05:15

所接受的答案在导致错误的原因中是正确的,但是您说您希望排序键是Value。因此,您应该将CloudFormation更改为包含以下内容:

代码语言:javascript
运行
复制
{
  "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"
          },
          { 
            "AttributeName": "Value", 
            "KeyType": "RANGE"
          }
        ]                
      },
      "TableName": "TableName"
    }
  }
}
票数 1
EN

Stack Overflow用户

发布于 2020-02-12 17:29:21

在AttributeDefinitions中,您需要只定义分区和范围键,而不是其他属性。

AttributeDefinitions和KeySchema中的属性数量应该匹配,并且应该完全相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41915749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档