amazon-web-servicesamazon-s3aws-cloudformation

Cloudformation : Encountered unsupported property DeletionPolicy on S3 Bucket


I am using below snippet to provision S3 Bucket using Cloudformation

and I want to Retain the S3 bucket and thus using DeletionPolicy.

Resources:
  S3Bucket:
    Type: 'AWS::S3::Bucket'
    Condition: ShouldCreateS3Bucket
    Properties:
      BucketName: !Ref S3BackupBucketName
      DeletionPolicy: Retain

But when i deploy this template i get the error

Encountered unsupported property DeletionPolicy

I referred to documentation and DeletionPolicy property exists

How should i resolve this issue ?

Thanks in advance.


Solution

  • It should be at S3Bucket level, not Properties:

    Resources:
      S3Bucket:
        Type: 'AWS::S3::Bucket'
        Condition: ShouldCreateS3Bucket
        DeletionPolicy: Retain 
        Properties:
          BucketName: !Ref S3BackupBucketName