Cloudformation : Encountered unsupported property DeletionPolicy on S3 Bucket

Viewed 958

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.

2 Answers

It should be at S3Bucket level, not Properties:

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

Recommend trying the CloudFormation Linter in VSCode to see some of these errors inline while authoring templates along with autocompletion and documentation links:

Visual Studio Code extension

[cfn-lint] E3002: Invalid Property Resources/S3Bucket/Properties/DeletionPolicy
Related