amazon-web-servicesyamlamazon-dynamodbaws-cloudformation

DB table deleted but not able to create a new one since it still has the old identifier


I manually deleted a db table in cloud formation and in my yaml template created a new one with new name but still getting an error telling :

Resource handler returned message: "Resource of type 'AWS::DynamoDB::Table' with identifier 'oldeName' already exists." ( HandlerErrorCode: AlreadyExists)

And when I look under my stack resources, I see that the logical id with the old name still exists but with no physical id and with a status that says DELETE_COMPLETE:

How could I fix this and create the new table successufully via sam yaml template ?


Solution

  • The error you’re seeing happens because CloudFormation keeps track of all resources it manages, even after they’ve been deleted. When you manually delete a resource (like your DynamoDB table), CloudFormation doesn’t forget about it. It still references the resource and tries to manage it during stack updates, which is why you’re running into the AlreadyExists error.

    so if you go to the Resources tab, try to find the old DynamoDB table. yo said it shows DELETE_COMPLETE with no physical ID, that means CloudFormation still thinks the resource exists, even though it doesn’t.

    an easy workaround here is to Rename the Logical ID in Your Template, that way , CloudFormation treats it as a brand-new resource and won’t try to reconcile it with the deleted one. you just need to make sure there are no dependencies or references in your YAML template or elsewhere in your stack pointing to the old table.

    and if there's nothing works, you can force delete your stack and re-apply it again. but the renaming will mostly work.