Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A simple tool that will help you enable MFA Delete feature on your S3 bucket
#!/usr/bin/env ruby
require 'aws'
if ARGV.length < 5
print <<-EOF
Usage: mfa-delete.rb <bucket_name> <aws_id> <aws_secret> <mfa_serial> <mfa_token> <s3_endpoint>
<s3_endpoint> is optional
bucket_name = ARGV[0]
aws_id = ARGV[1]
aws_key = ARGV[2]
mfa_serial = ARGV[3]
mfa_token = ARGV[4]
s3_endpoint = ARGV[5] || ""
s3 ={
:s3_endpoint => s3_endpoint,
:access_key_id => aws_id,
:secret_access_key => aws_key
bucket = s3.buckets[bucket_name]
bucket.enable_versioning :mfa_delete=>'Enabled', :mfa=>"#{mfa_serial} #{mfa_token}"

This comment has been minimized.

Copy link

leighmcculloch commented Sep 2, 2014

Helpful script, thanks. The require 'aws' needs to be require 'aws-sdk'.


This comment has been minimized.

Copy link

steve-jansen commented Sep 10, 2015

Super helpful.

'aws-sdk' v2 introduced breaking changes for this script.

My workaround:

cat << EOF > Gemfile
source ''
gem 'aws-sdk', '~> 1'
bundle install
bundle exec ruby mfa-delete.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.