0

The DynamoDB table is already created and running in production. As per current use-case, planning to add new secondary global index. This can be achieved via AWS SDK, is it possible to update DynamoDB table with CloudFormation script.

Any helps will be appreciated.

Ravikumar
  • 1,121
  • 1
  • 12
  • 23
  • 1
    You should not be using cloudformation for something like this. If the table was created in the first place with CF, then you can modify the resource and deploy it again. But CF is not meant for modifying existing resources unrelated to your stack. – 404 Nov 01 '19 at 10:11
  • Possible duplicate of https://stackoverflow.com/questions/54427486/incorporate-existing-aws-resources-into-a-cloudformation-stack – matt helliwell Nov 02 '19 at 13:06
  • I can able to create autoscaling policy for the same existing dynamo table using CF but not secondary index. This is specific to dynamoDB GSI and not duplicate of the one specified above question. – Ravikumar Nov 03 '19 at 23:24

1 Answers1

0

create a new or overwrite your current CloudFormation script with

Resources
 DDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: YOUR_EXISTING_TABLE_NAME
      AttributeDefinitions: #List out all existing cols here
        -
          AttributeName: "ColX" # hash key
          AttributeType: "S"
        -
          AttributeName: "ColY" # range key
          AttributeType: "S"
        -
          AttributeName: "ColZ" # used for your Global Secondary Index 
          AttributeType: "S"

      KeySchema: # List out your main Hash & Range Key
        -
          AttributeName: "ColX"
          KeyType: "HASH"
        -
          AttributeName: "ColY"
          KeyType: "RANGE"

      GlobalSecondaryIndexes: #  new Global Secondary Index
      - IndexName: INDEX_NAME
        KeySchema:
        - AttributeName: ColZ #different than your main table Hash Key
          KeyType: HASH
        Projection:
          ProjectionType: ALL

Ethan Nguyen
  • 104
  • 4
  • This script will try to create table with existing_table_name and failed with table already exists. – Ravikumar Nov 01 '19 at 04:57
  • Hope the table was created with CloudFormation in the first place. Otherwise, there is no way to take existing resources and get them included in a new CloudFormation stack. – Ethan Nguyen Nov 01 '19 at 06:35