Amazon Elastic Compute Cloud
User Guide (API Version 2012-04-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Automatically Attaching Volumes

By default, every Amazon EBS-backed AMI has a snapshot associated with it for the root device volume. Whenever you launch an instance of the AMI, that snapshot automatically instantiates and a volume for the root device attaches to the instance.

What if you want other volumes to automatically attach to your instance? You can easily do that by specifying a block device mapping when you register the image. You can register an image using the command line tools or API; you can't use the AWS Management Console. For more information about block device mappings, see Block Device Mapping.

Command Line Tools

You use ec2-register and specify a block device mapping that includes the additional volumes. In the example shown here, you register an AMI and attach two extra volumes (in addition to the root device volume).

[Note]Note

You cannot register an image where a secondary (non-root) snapshot has AWS Marketplace product codes.

To add additional volumes to the AMI

  • Use the ec2-register command with the block device mapping information. The following example registers an AMI with three volumes (one for the root device, and two extra):

    • The first is an 80 GiB root device volume at /dev/sda1 created from the snap-12345678 snapshot. The root volume's DeleteOnTermination flag is set to false. Remember that if you specify a size, it must be equal to or larger than the snapshot's size. You can omit a size value and the volume uses the snapshot's size.

    • The second volume is mapped to /dev/sdh and created from snapshot snap-88888888. The mapping uses the default size of the snapshot and doesn't specify a value for DeleteOnTermination. The default value is true.

    • The third volume is an empty 40 GiB volume mapped to /dev/sdj. The volume's DeleteOnTermination flag is set to false.

    PROMPT>  ec2-register -n My_Image_Name -d My_image_description --root-device-name /dev/sda1 -b /dev/sda1=snap-12345678:80:false -b /dev/sdh=snap-88888888 -b /dev/sdj=:40:false

    In response, you get the ID for your new AMI.

    IMAGE     ami-61a54008

Any instance of the AMI that you launch includes the three volumes by default.

You can view the AMI's or instance's block device mapping at any time. For more information, see Viewing Block Device Mappings.

API

You use RegisterImage and specify a block device mapping that includes the additional volumes. The following example registers an AMI and attaches two extra volumes (in addition to the root device volume).

[Note]Note

You cannot register an image where a secondary (non-root) snapshot has AWS Marketplace product codes.

To add additional volumes to the AMI

  • Issue the following Query request to register the image.

    The example registers an AMI with three volumes:

    • The first is an 80 GiB root device volume at /dev/sda1 created from the snap-12345678 snapshot. The root volume's deleteOnTermination flag is set to false. Remember that if you specify a size, it must be equal to or larger than the snapshot's size. If you omit a size value, the volume uses the snapshot's size.

    • The second volume is mapped to /dev/sdh and created from snapshot snap-88888888. The mapping uses the default size of the snapshot and doesn't specify a value for deleteOnTermination. The default value is true.

    • The third volume is an empty 40 GiB volume mapped to /dev/sdj. The volume's deleteOnTermination flag is set to false.

    https://ec2.amazonaws.com/
    ?Action=RegisterImage
    &Name=MyImage
    &KernelId=aki-f70657b2
    &RamdiskId=ari-ff0d5cba
    &RootDeviceName=/dev/sda1
    &BlockDeviceMapping.1.DeviceName=/dev/sda1
    &BlockDeviceMapping.1.Ebs.SnapshotId=snap-12345678
    &BlockDeviceMapping.1.Ebs.VolumeSize=80
    &BlockDeviceMapping.1.Ebs.DeleteOnTermination=false
    &BlockDeviceMapping.2.DeviceName=/dev/sdh
    &BlockDeviceMapping.2.Ebs.SnapshotId=snap-88888888
    &BlockDeviceMapping.3.DeviceName=/dev/sdj
    &BlockDeviceMapping.3.Ebs.VolumeSize=40
    &BlockDeviceMapping.3.Ebs.DeleteOnTermination=false
    &...auth parameters...

    For information about the auth parameters, go to Common Query Parameters in the Amazon Elastic Compute Cloud API Reference.

    Following is an example response.

    <RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2012-04-01/">
       <imageId>ami-61a54008</imageId>
    </RegisterImageResponse>

Any instance of the AMI that you launch includes the three volumes by default.

You can view the AMI's or instance's block device mapping at any time. For more information, see Viewing Block Device Mappings.