Clean S3 Bucket on CloudFormation Delete

Annoyingly CloudFormation doesn’t delete S3 buckets that have contents which led to work arounds such as retaining the bucket on delete or creating the bucket outside of CloudFormation. However we have just released a CloudFormation custom resource to delete the contents of a bucket when deleting a S3 bucket. The custom resource is available as cfhighlander component making it easy to plugin and consume in a cfhighlander project.

To use in your project simply include the component and pass in a comma delimited list of bucket names in your cfhighlander.rb file

CfhighlanderTemplate do

  Component name: 'bucket', template: 's3'

  Component name: 'S3CleanupOnDelete', template: 's3-cleanup-on-delete' do
    parameter name: 'Buckets', value: cfout('bucket.MyBucket')
  end
end

Source: https://github.com/theonestack/hl-component-s3-cleanup-on-delete