DeletionPolicy attribute in CloudFormation

In AWS CloudFormation, all resource types have a DeletionPolicy attribute with possible values of Delete, Retain and Snapshot. Setting it to Retain would save the resource from being deleted by mistake.

If no deletion policy is specified for a resource, the default value is Delete. It means the resource will be removed as part of the CloudFormation stack removal.

For resources with a Retain deletion policy, when the stack is deleted, AWS CloudFormation leaves the resource without deleting it.

However, it does NOT stop the resource from being deleted directly:

  • Programmatically, i.e. using AWS CLI tool.
  • Manually, i.e. using the AWS web console.

With the DeletionPolicy attribute you can preserve or (in some cases) backup a resource when its stack is deleted. Resources that support Snapshot deletion policy include:

More information about Deletion Policy can be found at AWS documentation.

A example showing how to specify DeletionPolicy

Software developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store