Skip to content

Instantly share code, notes, and snippets.

@pingali
Created March 26, 2009 19:23
Show Gist options
  • Save pingali/86258 to your computer and use it in GitHub Desktop.
Save pingali/86258 to your computer and use it in GitHub Desktop.
# Courtesy
# http://ec2dream.blogspot.com/search/label/EBS
#!/usr/bin/ruby
require 'rubygems'
require 'right_aws'
require 'net/http'
url = 'http://169.254.169.254/2008-02-01/meta-data/instance-id'
instance_id = Net::HTTP.get_response(URI.parse(url)).body
AMAZON_PUBLIC_KEY=''
AMAZON_PRIVATE_KEY=''
url_user_data = 'http://169.254.169.254/2008-02-01/user-data'
ec2_vol = Net::HTTP.get_response(URI.parse(url_user_data)).body
print "auto mounting ",ec2_vol,"\n"
ec2 = RightAws::Ec2.new(AMAZON_PUBLIC_KEY, AMAZON_PRIVATE_KEY)
print "attach ",ec2_vol,"\n"
vol = ec2.attach_volume(ec2_vol, instance_id, '/dev/sdf')
puts vol
# It can take a few seconds for the volume to become ready.
# This is just to make sure it is ready before mounting it.
sleep 20
print "mount /dev/sdf /mnt/data01\n"
system('mkdir /mnt/data01')
system('mount /dev/sdf /mnt/data01')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment