Shashi
Shashi

Reputation: 315

Cloudformation deletion deleting the S3 bucket in spite of DeletionPolicy: Retain

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

Answers (2)

Shashi
Shashi

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.

enter image description here

Upvotes: 0

H.G.
H.G.

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.CloudFormation page

Double check your results.

Upvotes: 4

Related Questions