Skip to content

Instantly share code, notes, and snippets.

@leighmcculloch
Forked from petethepig/mfa-delete.rb
Last active November 7, 2015 17:29
Show Gist options
  • Save leighmcculloch/a48f826b97789f8d341d to your computer and use it in GitHub Desktop.
Save leighmcculloch/a48f826b97789f8d341d 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-sdk-v1'
print "S3 bucket name: "
bucket_name = STDIN.gets.chomp
print "AWS Access Key ID: "
aws_id = STDIN.gets.chomp
print "AWS Access Secret Key: "
aws_key = STDIN.gets.chomp
print "AWS Root MFA Serial: "
mfa_serial = STDIN.gets.chomp
print "AWS Root MFA Token: "
mfa_token = STDIN.gets.chomp
print "AWS Endpoint (s3.amazonaws.com): "
s3_endpoint = STDIN.gets.chomp
s3_endpoint = "s3.amazonaws.com" if s3_endpoint.length == 0
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