Reputation: 315
I have a cloud formation template with the following, if I delete the stack the bucket still deletes even though the bucket DeletionPolicy
is Retain
.
Resources:
mybucket123:
Type: 'AWS::S3::Bucket'
DeletionPolicy: Retain
Properties:
AccessControl: Private
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
Outputs:
S3Bucket:
Description: Test CFT to create a bucket.
Value: !Ref mybucket123
Upvotes: 0
Views: 2892
Reputation: 315
Looks like the issue was not in template but in the way i wrote in designer, went to the template tab at the bottom of designer and saved the code and validated the template,created stack and worked fine.
Upvotes: 0
Reputation: 413
Using the same template you have provided with an added property of BucketName
I got the expected behavior as described in the AWS CloudFormation documentation on DeletionPolicy.
If you specify the DeletionPolicy to Retain on an S3 Bucket resource, the deletion of the resource will be skipped. To validate this, check the resource tab of the CloudFormation Stack (as attached). Status of your S3 resource will be DELETE_SKIPPED. What might be confusing to you is that the stack itself is now gone, but this is expected after a stack deletion action. Also, if you open Amazon S3 page within the AWS Management Console your resource will still be there.
Double check your results.
Upvotes: 4