0
votes

I tried to write cloud formation script for creating dynamodb. When i execute script its getting error already exists in stack.

This is my template.

AWSTemplateFormatVersion: "2010-09-09"
Resources: 
  terminationLettersDynamodb:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Delete
      Properties:
        AttributeDefinitions:
          - AttributeName: schemeId
            AttributeType: S

        KeySchema:
          - AttributeName: schemeId
            KeyType: HASH

        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: "terminationLetters"

Is there any way to delete resource before creating.?

1
The error indicates that you have one or more custom-named resources with the same name. An example would be: you have 2 DynamoDB tables with the same name: terminationLetters. Check your resource names. Here's an article from AWS explaining this exact error: aws.amazon.com/premiumsupport/knowledge-center/….krishna_mee2004
I need to drop existing table and recreate.Thiwanka Wickramage

1 Answers

1
votes

You should avoid using hardcoded table names. If you specify a name, you cannot perform updates that require replacement of this resource.

When leaving out the TableName, you can reference the dynamically created table name elsewhere in your stack with the Ref intrinsic function, e.g.: Ref "terminationLettersDynamodb"