【发布时间】:2016-08-23 10:31:29
【问题描述】:
我有一个现有的 DynamoDB 表,它被定义为 CloudFormation 堆栈的一部分。根据CFN AWS::DynamoDB::Table documentation GlobalSecondaryIndexes 属性不需要替换。它甚至详细介绍了以下警告。
您可以不间断地删除或添加一个全局二级索引。
还有以下...
如果您更新表以包含新的全局二级索引,AWS CloudFormation 启动索引创建,然后继续 堆栈更新。 AWS CloudFormation 不会等待索引 完成创建,因为回填阶段可能需要很长时间, 取决于桌子的大小。
但是,实际上,当我尝试执行更新时,会收到以下错误消息:
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename mytablename and update the stack again.
由于我添加了一个使用新属性的 GSI,我不得不修改 AttributeDefinitions,它说它确实需要替换。但是,即使我尝试添加仅在 AttributeDefinitions 中定义的现有属性的 GSI,我仍然会收到相同的错误消息。
这是我的表的原始 CFN 定义中的 sn-p:
{
"myTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "mytablename",
"AttributeDefinitions": [
{
"AttributeName": "entryId",
"AttributeType": "S"
},
{
"AttributeName": "entryName",
"AttributeType": "S"
},
{
"AttributeName": "appId",
"AttributeType": "S"
}
],
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "entryId"
},
{
"KeyType": "RANGE",
"AttributeName": "entryName"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "readThroughput"
},
"WriteCapacityUnits": {
"Ref": "writeThroughput"
}
},
"GlobalSecondaryIndexes": [
{
"IndexName": "appId-index",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "appId"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "readThroughput"
},
"WriteCapacityUnits": {
"Ref": "writeThroughput"
}
}
}
]
}
}
}
这是我想要更新的内容:
{
"myTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "mytablename",
"AttributeDefinitions": [
{
"AttributeName": "entryId",
"AttributeType": "S"
},
{
"AttributeName": "entryName",
"AttributeType": "S"
},
{
"AttributeName": "appId",
"AttributeType": "S"
},
{
"AttributeName": "userId",
"AttributeType": "S"
}
],
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "entryId"
},
{
"KeyType": "RANGE",
"AttributeName": "entryName"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "readThroughput"
},
"WriteCapacityUnits": {
"Ref": "writeThroughput"
}
},
"GlobalSecondaryIndexes": [
{
"IndexName": "appId-index",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "appId"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "readThroughput"
},
"WriteCapacityUnits": {
"Ref": "writeThroughput"
}
}
},
{
"IndexName": "userId-index",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "userId"
}
],
"Projection": {
"ProjectionType": "KEYS_ONLY"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "readThroughput"
},
"WriteCapacityUnits": {
"Ref": "writeThroughput"
}
}
}
]
}
}
}
但是,就像我之前提到的那样,即使我没有在 AttributeDefinitions 中定义 userId 并在新的 GSI 定义中使用现有属性,它也不起作用并且失败并显示相同的错误消息。
【问题讨论】:
-
我可以确认,当我尝试添加 GSI 而不对 AttributeDefinitions 进行任何更改时,也会发生同样的情况。该文档还指出:“更新要求:不支持更新。除了以下例外:如果仅更新全局二级索引的预置吞吐量值,则可以不间断地更新表。您可以删除或添加一个全局二级索引索引而不会中断。如果您在同一更新中同时执行这两项操作(例如,通过更改索引的逻辑 ID),更新将失败。"
标签: amazon-web-services amazon-dynamodb amazon-cloudformation