我在cloudformation中使用下面的模板来创建dynamoDB表。我想要创建一个以PrimaryKey作为ID,sortKey作为值的表
{
"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和辅助索引不一致。
发布于 2020-02-12 18:05:15
所接受的答案在导致错误的原因中是正确的,但是您说您希望排序键是Value。因此,您应该将CloudFormation更改为包含以下内容:
{
"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"
}
}
}发布于 2020-02-12 17:29:21
在AttributeDefinitions中,您需要只定义分区和范围键,而不是其他属性。
AttributeDefinitions和KeySchema中的属性数量应该匹配,并且应该完全相同。
https://stackoverflow.com/questions/41915749
复制相似问题