Serverless Error, CloudFormation cannot update a stack when a custom-named resource requires replacing

Joseph Astrahan picture Joseph Astrahan · Nov 30, 2017 · Viewed 7.8k times · Source

I have the following error.

Serverless: Operation failed!

Serverless Error ---------------------------------------
An error occurred: phoneNumberTable - CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename mysite-api-phonenumber-dev and update the stack again…

I tried deleting the database to see if it could re-create it then but it still gives the same error and doesn’t remake the database? What do I do here?

What I did was recently change in my serverless.yml file the following for the resource.

phoneNumberTable: #This table is used to track phone numbers used in the system
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.phoneNumberTable}
        AttributeDefinitions: #UserID in this case will be created once and constantly updated as it changes with status regarding the user.
          - AttributeName: phoneNumber
            AttributeType: S
        KeySchema:
          - AttributeName: phoneNumber
            KeyType: HASH
        ProvisionedThroughput:
            ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
            WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}

I accidentally created it with userId when I was copying and pasting so I changed it to phoneNumber for the hash key but the change won't reflect now!

Edit::

I found a solution but it's terrible. If I do sls remove --stage dev it will remove everything for my stage, but literally everything... then I have to do sls deploy --stage dev to start the deploy over again, in the meantime my database is cleared of all data... there has to be a better way somehow.

Answer

Jon Smirl picture Jon Smirl · Nov 30, 2017