Created
November 8, 2012 02:23
-
-
Save brock/4036168 to your computer and use it in GitHub Desktop.
Delete all files in s3 bucket
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
# Credit to MattLor | |
# http://stackoverflow.com/questions/27267/delete-amazon-s3-buckets | |
require 'aws/s3' | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => 'your access key', | |
:secret_access_key => 'your secret key' | |
) | |
bucket = AWS::S3::Bucket.find('bucketName') | |
while(!bucket.empty?) | |
begin | |
puts "Deleting objects in bucket" | |
bucket.objects.each do |object| | |
object.delete | |
puts "There are #{bucket.objects.size} objects left in the bucket" | |
end | |
puts "Done deleting objects" | |
rescue SocketError | |
puts "Had socket error" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment