Last Updated: September 24, 2016
·
1.482K
· whatupdave

Delete all your S3 buckets with ease

This is a quick ruby script that will delete all your S3 buckets in 24 hours.

#!/usr/bin/env ruby

require 'rubygems'
require 'fog'

# create a connection
connection = Fog::Storage.new({
    :provider                   => 'AWS',
    :aws_access_key_id          => ENV['AWS_ACCESS_KEY'],
    :aws_secret_access_key      => ENV['AWS_SECRET_KEY']
})

life_cycle = {
  "Rules" => [{
    'Expiration' => { "Days" => 1, "Date" => Time.now.utc }
  }]
}

connection.directories.each do |dir|
  puts "DELETE #{dir.key}"
  connection.put_bucket_lifecycle(dir.key, life_cycle)
end

USE WITH CAUTION HOLY SHIT

1 Response
Add your response

nice!

over 1 year ago ·