Search code examples
amazon-web-servicesaws-cloudformationaws-cliaws-cloudformation-custom-resource

Delete AWS Cloud formation stack with resources created by it


Based on this page I can do:

aws cloudformation delete-stack \
    --stack-name my-stack

It says I can attach the command: [--retain-resources <value>]

Does that mean that if I don't specify that line, all the resources created by the stack will be removed? I'm trying to delete everything generated by the stack, which is a lot.

How can I achieve this?

Thanks


Solution

  • Yes, those resources will be kept if you specify the [--retain-resources <value>], if you dont Cloudformation will delete all the resources in the stack name (including the nested stacks as well) you are providing given you have permissions to do. If any of the resources inside the cloudformation stack has retain policy set they won't be deleted.

    During deletion, AWS CloudFormation deletes the stack but does not delete the retained resources.

    From the same page aws cloudformation delete-stack

    You might wanna read this too How do I retain some of my resources when I delete an AWS CloudFormation stack?

    You can specify the retain policy as well in cloudformation template.