PropertyDefinition不一致
PropertyDefinition inconsistent
我在 cloudformation UI 中使用以下模板来创建 dynamoDB table。我想创建一个 table 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 UI 上,我单击新堆栈,指向本地计算机中的 template
文件,为堆栈命名并单击下一步。一段时间后,我收到错误提示 属性 AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes
问题是 Resources.Properties.AttributeDefinitions
键必须 仅 定义用于索引或键的列。换句话说,Resources.Properties.AttributeDefinitions
中的键必须匹配 Resources.Properties.KeySchema
.
中定义的相同键
AWS 文档:
AttributeDefinitions: A list of AttributeName and AttributeType objects that describe the key schema for the table and indexes.
因此生成的模板将如下所示:
{
"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"
}
}
}
}
在 AttributeDefinitions 中,您只需定义分区键和范围键,而不是其他属性。
AttributeDefinitions 和 KeySchema 中的属性数量应该匹配并且应该完全相同。
接受的答案在错误原因上是正确的,但您说您希望排序键是 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"
}
}
}
我在 cloudformation UI 中使用以下模板来创建 dynamoDB table。我想创建一个 table 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 UI 上,我单击新堆栈,指向本地计算机中的 template
文件,为堆栈命名并单击下一步。一段时间后,我收到错误提示 属性 AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes
问题是 Resources.Properties.AttributeDefinitions
键必须 仅 定义用于索引或键的列。换句话说,Resources.Properties.AttributeDefinitions
中的键必须匹配 Resources.Properties.KeySchema
.
AWS 文档:
AttributeDefinitions: A list of AttributeName and AttributeType objects that describe the key schema for the table and indexes.
因此生成的模板将如下所示:
{
"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"
}
}
}
}
在 AttributeDefinitions 中,您只需定义分区键和范围键,而不是其他属性。
AttributeDefinitions 和 KeySchema 中的属性数量应该匹配并且应该完全相同。
接受的答案在错误原因上是正确的,但您说您希望排序键是 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"
}
}
}