gpt4 book ai didi

amazon-web-services - 无法使用 CloudFormation 将 GSI 添加到 DynamoDB 表

转载 作者:行者123 更新时间:2023-12-03 23:40:00 26 4
gpt4 key购买 nike

我有一个现有的 DynamoDB 表,该表定义为 CloudFormation 堆栈的一部分。根据CFN AWS::DynamoDB::Table documentation GlobalSecondaryIndexes 属性不需要替换。它甚至还详细介绍了以下注意事项。

You can delete or add one global secondary index without interruption.

以及以下...

If you update a table to include a new global secondary index, AWS CloudFormation initiates the index creation and then proceeds with the stack update. AWS CloudFormation doesn't wait for the index to complete creation because the backfilling phase can take a long time, depending on the size of the table.

但是,实际上,当我尝试执行更新时,我收到以下错误消息:

CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename mytablename and update the stack again.

由于我添加了使用新属性的 GSI,因此我被迫修改 AttributeDefinitions,它表示它确实需要替换。但是,即使当我尝试添加仅包含 AttributeDefinitions 中定义的现有属性的 GSI 时,我仍然收到相同的错误消息。

以下是我的表的原始 CFN 定义的片段:

{
"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 定义中使用现有属性,它也不起作用,并且会失败并显示相同的错误消息。

最佳答案

我今天遇到了同样的错误,并从亚马逊技术支持那里得到了答案。问题是您提供了一个 TableName 字段。 CloudFormation 希望负责为您命名表。显然,当您为它们提供自己的名称时,这是在替换表的更新中遇到的错误(不确定为什么需要替换,但这就是文档所说的)

对我来说,这使得 CloudFormation 对于维护我的 DynamoDB 表毫无用处。我必须构建配置,以便我的代码可以动态地告诉 CloudFormation 为我生成的随机表名称。

关于amazon-web-services - 无法使用 CloudFormation 将 GSI 添加到 DynamoDB 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36918408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com