Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2013 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4662604 to your computer and use it in GitHub Desktop.
Save anonymous/4662604 to your computer and use it in GitHub Desktop.
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
EOF
exit
end
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.amazonaws.com"
s3 = AWS::S3.new({
: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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment