| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
The DeletionPolicy attribute enables you to specify how AWS CloudFormation handles the resource deletion. By adding a DeletionPolicy to a resource, you can control how AWS CloudFormation handles the resource when its stack is deleted. By default, AWS CloudFormation deletes the resource if it has no DeletionPolicy attribute. You can specify Retain for AWS CloudFormation to leave a resource without deleting it. For resources that support snapshots, such as AWS::RDS::DBInstance and AWS::EC2::Volume, you can specify Snapshot for AWS CloudFormation to create a snapshot before deleting the resource.
For example, the following template contains an Amazon S3 bucket resource with a Retain deletion policy. When this stack is deleted, AWS CloudFormation will leave the bucket without deleting it.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"myS3Bucket" : {
"Type" : "AWS::S3::Bucket",
"DeletionPolicy" : "Retain"
}
}
} Default. This policy directs AWS CloudFormation to delete the resource and all its content if applicable during stack deletion. You can add this deletion policy to any resource type.
Note
For S3 buckets, deletion will succeed only if the bucket is empty.
This policy directs AWS CloudFormation to keep the resource without deleting the resource or its contents, as applicable, during stack deletion. You can add this deletion policy to any resource type. Note that when AWS CloudFormation completes the stack deletion, the stack will be in Delete_Complete state; however, resources with a Retain policy will continue to exist and will continue to incur applicable charges until you delete those resources.
This policy is allowed only for resources that support snapshots: AWS::RDS::DBInstance and AWS::EC2::Volume. This policy directs AWS CloudFormation to create a snapshot for the resource before deleting the resource. Note that when AWS CloudFormation completes the stack deletion, the stack will be in the Delete_Complete state; however, the snapshots created with this policy will continue to exist and continue to incur applicable charges until you delete those snapshots.