Skip to content

Instantly share code, notes, and snippets.

@brock
Created November 8, 2012 02:23
Show Gist options
  • Save brock/4036168 to your computer and use it in GitHub Desktop.
Save brock/4036168 to your computer and use it in GitHub Desktop.
Delete all files in s3 bucket
# 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