- Newest
- Most votes
- Most comments
To address your CloudFormation drift issue and reprovision the accidentally deleted resources without deleting the entire stack, you can follow these steps:
-
First, identify the logical IDs of the resources that were deleted outside of the CloudFormation stack.
-
In your CloudFormation template, assign new logical IDs to these deleted resources. For example, if you had an S3 bucket with the logical ID "S3Bucket", you could rename it to "S3NewBucket".
-
Update all references to the old logical IDs throughout your template, replacing them with the new logical IDs you just created.
-
After making these changes, update your CloudFormation stack using the modified template. This update operation will cause CloudFormation to recreate the deleted resources with the new logical IDs, while leaving the existing resources untouched.
It's important to note that this method works because CloudFormation interprets the resources with new logical IDs as new resources to be created, rather than updates to existing (but deleted) resources.
After performing these steps, you should run a drift detection operation on your stack to ensure that all resources are now in sync with the template.
If you encounter any issues during this process, you may need to check for dependencies between resources or review the specific error messages provided by CloudFormation. In some cases, you might need to adjust the order of resource creation or add explicit dependencies using the DependsOn attribute in your template.
Remember that drift detection might not always provide perfectly accurate results in all scenarios, so it's crucial to double-check the actual state of your resources after performing these operations.
Sources
Recreate a resource deleted outside CloudFormation | AWS re:Post
Detect unmanaged configuration changes to stacks and resources with drift detection - AWS CloudFormation
Troubleshooting CloudFormation - AWS CloudFormation
Hi,
You probably want to follow precisely the steps of this KC article: https://repost.aws/knowledge-center/cfn-recreate-resource-deleted-outside
Best
Didier
Relevant content
asked 2 years ago
