My use case is that we already have a stack created out of AWS Cloudformation.
Now I want to update that stack and my requirement is that I want to delete a resource that was already created and add the new modified resource but I want to make sure that the delete happens before the create part.
I explored the dependsOn but that helps me with setting the order of resource creation. It doesn’t help with ensuring the delete and the create ordering (or atleast nothing that i could find)
How to make sure that the resource deletion happens before resource creation while doing the cloudformation update
I understand you want to,
delete a resource that was already created and add the new modified
Below is my understanding, let me know if it helps,
It is very trickey to Delete and Create resource having same resource name/dependency in a single CloudFormation deployment.
Easiest approach :
- First deploy CFN template to Delete a resource i.e. remove the code
from template and than add new resource/modified one. While doing
that you need to check if “retention policy” is in place because if
you are retaining deleted resources than CloudFormation will not
create same resource again.
- Than deploy the CFN template to create/modify resources
Other approach might be:
- If you want to ensure the resource deletes before creating new one,
in a single template, you might need to create a nested stack
for resource deletion and resource creation
- And add dependency on the deletion cloudFormation template i.e.
Create resource template will depends on Delete resource template.
There are also AWS::CloudFormation::WaitCondition which can be
Also I think anyway you will receive an error if you try to create/modify on deleted/ delete in-progress resource