Before you delete a stack, make sure that you specify the Retain, Snapshot, or Delete policy option for each resource that you want to keep:
The Retain option keeps the resource in case there's a stack deletion.
The Snapshot option creates a snapshot of the resource before that resource is deleted. Note: This option is available only for resources that support snapshots.
The Delete option deletes the resource along with the stack. Note: This option is the default outcome if you don't set a DeletionPolicy.
The following steps show you how to use the Retain option for DeletionPolicy to prevent the deletion of resources during a CloudFormation stack deletion.
Specify the DeletionPolicy attributes in the AWS CloudFormation template
In your CloudFormation template, enter Retain as the DeletionPolicy for the resources that you want to keep. In the following example JSON and YAML templates, the Retain policy is specified for AWS::EC2::SecurityGroup resources.
Confirm that the resources with the Retain option for DeletionPolicy are still available after the stack deletion is complete. You can check the resources in their respective services using the AWS Management Console or the AWS CLI.
For example, you can verify the success of the Retain policy for the preceding templates by using the following steps after you deleted the CloudFormation stack.