Unable to add GSI to DynamoDB table using CloudFormation

I have an existing DynamoDB table that is defined as part of the CloudFormation stack. According to CFN AWS ​​:: DynamoDB :: Documentation Table, the GlobalSecondaryIndexes attribute does not need to be replaced. It is even detailed with the following reservations.

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

Like the following ...

If you refresh the table to include the new global secondary index, AWS CloudFormation initiates the creation of the index, and then goes to the stack. AWS CloudFormation does not wait until the index is fully created, because the backfill phase can take a long time, depending on the size of the table.

However, in practice, when I try to upgrade, the following error message appears:

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

Since I am adding a GSI that uses the new attribute, I am forced to modify AttributeDefinitions, which says it needs to be replaced. However, even when I try to add GSI only with existing attributes defined in the AttributeDefinitions attributes, I still get the same error message.

Here is a snippet from my original CFN definition for my table:

{
  "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"
            }
          }
        }
      ]
    }
  }
}

Here is what I want to upgrade to:

{
  "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"
            }
          }
        }
      ]
    }
  }
}

However, as I mentioned earlier, even if I do not define userId in the AttributeDefinitions attributes and use the existing attribute in the new GSI definition, it does not work and does not work with the same error message.

+4
3

, Amazon. , TableName. CloudFormation , . -, , , , ( , , , )

CloudFormation DynamoDB. , , CloudFormation.

+5

AWS FWIW:

A

: . / , .

B

  • CloudFormation
  • AWS SDK , , , .

, (- / ), . * http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudFormation.html#describeStackResource-property

, , , , . .

+3

DynamoDB, , , :

:

node ./node_modules/serverless/bin/serverless remove

:

serverless remove

, :

node ./node_modules/serverless/bin/serverless deploy -v

serverless deploy
+2
source

All Articles