Last active
December 17, 2015 14:29
-
-
Save rodolfo42/5625123 to your computer and use it in GitHub Desktop.
Deletes all objects in a S3 bucket, so you can finally delete it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deletes all objects in a S3 bucket, so you can finally delete it | |
# inspired by | |
# http://stackoverflow.com/a/1179190 | |
require 'aws' | |
require 'yaml' | |
credentials = { | |
:access_key_id => 'YOUR_ACCESS_KEY_ID', | |
:secret_access_key => 'YOUR_SECRET_ACCESS_KEY' | |
} | |
bucket_name = 'YOUR_BUCKET_NAME' | |
AWS.config(credentials) | |
s3 = AWS::S3.new | |
bucket = s3.buckets.find(bucket_name).first | |
while(!bucket.empty?) | |
begin | |
puts "Deleting objects in bucket #{bucket_name}" | |
bucket.objects.each do |object| | |
print "> Deleting object #{object.key} ..." | |
object.delete | |
puts "done" | |
end | |
puts "Done deleting objects" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment