Amazon S3: easily bulk delete buckets

With Jabbakam we save a lot of images. All these images are stored in Amazon’s S3. Recently I thought I’d delete some of the test buckets.

Not as easy as I first thought. It turns out that you have to empty buckets before you can delete them. Fair enough, but there didn’t seem to be a way to easily bulk delete hundreds of images.

After some Googling I found Robert LaThanh’s S3Nukem which looked like it would do the job. All I needed to do now was fire up an EC2 instance, install and run. The steps were as follows:

  1. Create an EC2 instance on AWS (I used Ubuntu on a medium instance)
  2. make sure it is all up-to-date
    apt-get update
    apt-get upgrade
  3. install ruby (if not already installed)
    apt-get install ruby1.8 ruby1.8-dev

    (not sure about ruby1.8-dev, but added just in case)

  4. install Ruby Gems
    apt-get install rubygems
  5. install right_aws and s3nukem
    gem install right_aws
    cd /tmp
    wget http://github.com/lathanh/s3nukem/raw/master/s3nukem --no-check-certificate
    chmod +x s3nukem
  6. run
    ./s3nukem -t 20 -a  -s

Several hours and over 15 million deleted images later it was all done and I shut down the instance.

  • http://twitter.com/halfageekinfo 1/2ageek

    Thanks. Worked perfectly when someone spammed my buckets

  • http://twitter.com/halfageekinfo 1/2ageek

    Thanks. Worked perfectly when someone spammed my buckets