Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to create a EBS volume from and attach it to the same instance? will boto be of some help?

share|improve this question
up vote 5 down vote accepted

Yes it is. Set your credentials as environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY), install boto and fire up Python:

 >>> import boto
 >>> ec2 = boto.connect_ec2()
 >>> reservations = ec2.get_all_instances()
 >>> ins = reservations.instances[0]        # say ins is *this* instance
 >>> vol = ec2.create_volume(10, ins.placement)
 >>> vol.attach(, '/dev/sdh')

The above assumes you have only one instance started. If you know your instance id (you should!) you can simply match on the instance ids over all instances for all reservations.

Eventually you can simply format your volume and mount it:

 # mkfs -t ext3 /dev/sdh
 # mkdir /volume
 # mount -t ext3 /dev/sdh /volume
share|improve this answer

I think getting the instance ID dynamically is a better option. You can improve the above script with a GET request to the following URL within the instance.

Then you can write one script that'll work for all instances. Even if you just have one at a time, you can include this script in a custom AMI so each new instance can give itself a new volume if needed.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.