Add block device mappings to an AMI - Amazon Elastic Compute Cloud

Add block device mappings to an AMI

Each AMI has a block device mapping that specifies the block devices to attach to an instance when it is launched from the AMI. To add more block devices to an AMI, you must create your own AMI.

Specify a block device mapping for an AMI

There are two ways to specify volumes in addition to the root volume when you create an AMI. If you've already attached volumes to a running instance before you create an AMI from the instance, the block device mapping for the AMI includes those same volumes. For EBS volumes, the existing data is saved to a new snapshot, and it's this new snapshot that's specified in the block device mapping. For instance store volumes, the data is not preserved.

For an EBS-backed AMI, you can add EBS volumes and instance store volumes using a block device mapping. For an instance store-backed AMI, you can add instance store volumes only by modifying the block device mapping entries in the image manifest file when registering the image.

Note

For M3 instances, you must specify instance store volumes in the block device mapping for the instance when you launch it. When you launch an M3 instance, instance store volumes specified in the block device mapping for the AMI may be ignored if they are not specified as part of the instance block device mapping.

Console
To add volumes to an AMI using the console
  1. Open the Amazon EC2 console.

  2. In the navigation pane, choose Instances.

  3. Select an instance and choose Actions, Image and templates, Create image.

  4. Enter a name and a description for the image.

  5. The instance volumes appear under Instance volumes. To add another volume, choose Add volume.

  6. For Volume type, choose the volume type. For Device choose the device name. For an EBS volume, you can specify additional details, such as a snapshot, volume size, volume type, IOPS, and encryption state.

  7. Choose Create image.

Command line

To add volumes to an AMI using the command line

Use the create-image AWS CLI command to specify a block device mapping for an EBS-backed AMI. Use the register-image AWS CLI command to specify a block device mapping for an instance store-backed AMI.

Specify the block device mapping using the --block-device-mappings parameter. Arguments encoded in JSON can be supplied either directly on the command line or by reference to a file:

--block-device-mappings [mapping, ...] --block-device-mappings [file://mapping.json]

To add an instance store volume, use the following mapping.

{ "DeviceName": "device_name", "VirtualName": "ephemeral0" }

To add an empty 100 GiB gp2 volume, use the following mapping.

{ "DeviceName": "device_name", "Ebs": { "VolumeSize": 100 } }

To add an EBS volume based on a snapshot, use the following mapping.

{ "DeviceName": "device_name", "Ebs": { "SnapshotId": "snap-xxxxxxxx" } }

To omit a mapping for a device, use the following mapping.

{ "DeviceName": "device_name", "NoDevice": "" }

Alternatively, you can use the -BlockDeviceMapping parameter with the following commands (AWS Tools for Windows PowerShell):

View the EBS volumes in an AMI block device mapping

You can easily enumerate the EBS volumes in the block device mapping for an AMI.

Console
To view the EBS volumes for an AMI using the console
  1. Open the Amazon EC2 console.

  2. In the navigation pane, choose AMIs.

  3. Choose EBS images from the Filter list to get a list of EBS-backed AMIs.

  4. Select the desired AMI, and look at the Details tab. At a minimum, the following information is available for the root device:

    • Root Device Type (ebs)

    • Root Device Name (for example, /dev/sda1)

    • Block Devices (for example, /dev/sda1=snap-1234567890abcdef0:8:true)

    If the AMI was created with additional EBS volumes using a block device mapping, the Block Devices field displays the mapping for those additional volumes as well. (This screen doesn't display instance store volumes.)

Command line

To view the EBS volumes for an AMI using the command line

Use the describe-images (AWS CLI) command or Get-EC2Image (AWS Tools for Windows PowerShell) command to enumerate the EBS volumes in the block device mapping for an AMI.