- Newest
- Most votes
- Most comments
Hi Didier,
Thanks for the prompt response. Actually the default value for "DeletionPolicy" is delete and NICs are already deleted when the CFN stack is deleted. What we are looking for is to delete NICS when somebody terminates an instance attached to a CFN. Any ideas?
Best Regards, CG
Hi,
To achieve what you want you need to combine 2 CloudFormation features applicable to all kinds of resources that you create with your CFN template.
You have to use DependsOn to create but also in your case to destroy resources like the NICs in right order:
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html
- https://deepdive.codiply.com/cloudformation-resource-creation-and-deletion-order
And you also have to you DeletionPolicy to make sure that your resources are properly deleted:
Delete is probably the option that you are looking for
Delete
CloudFormation deletes the resource and all its content if applicable during stack deletion.
You can add this deletion policy to any resource type
Update on your response: to delete NICS when somebody terminates instance, you need to additionally configure in your CFN a Lambda triggered by the corresponding EventBridge event signalling EC2 instance termination in general. This Lambda will list the resources of the stack to which it belongs (to ensure that it acts on proper EC2 termination). If terminated EC2 is in the stack, it will then delete the NICs.
Best, Didier
Relevant content
- asked 5 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago
Hi CG, I update my initial response with an update. It should do what you need.