When working with AWS EC2 instance store-backed instances, creating AMIs involves specific device naming conventions that differ from EBS-backed instances. The error typically occurs during the RegisterImage
API call when the block device mapping in your manifest file contains incorrect device naming.
From the provided system information:
lsblk output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 500G 0 part /
xvdb 202:16 0 745.2G 0 disk
└─xvdb1 202:17 0 745.2G 0 part /media/ephemeral0
xvdc 202:32 0 745.2G 0 disk
└─xvdc1 202:33 0 745.2G 0 part /media/ephemeral1
The problematic manifest section:
<mapping>
<virtual>root</virtual>
<device>/dev/xvda1</device>
</mapping>
For instance store-backed AMIs, you should:
- Use the base device name (xvda) without partition number
- Omit the /dev/ prefix in the manifest
- Keep ephemeral mappings as shown in your current manifest
Modify your manifest file as follows:
<machine_configuration>
<architecture>x86_64</architecture>
<block_device_mapping>
<mapping>
<virtual>ami</virtual>
<device>xvda</device>
</mapping>
<mapping>
<virtual>ephemeral0</virtual>
<device>xvdb</device>
</mapping>
<mapping>
<virtual>ephemeral1</virtual>
<device>xvdc</device>
</mapping>
<mapping>
<virtual>root</virtual>
<device>xvda</device>
</mapping>
</block_device_mapping>
</machine_configuration>
With the corrected manifest, use this AWS CLI command:
aws ec2 register-image \
--name "MyInstanceStoreAMI" \
--description "AMI from instance store" \
--architecture x86_64 \
--root-device-name xvda \
--block-device-mappings file://manifest.xml
Before registration, verify your bundle upload:
aws ec2 describe-bundle-tasks \
--bundle-ids bun-xxxxxxxx
Check for any warnings or errors in the bundle task output that might affect registration.
When attempting to create an AMI from an instance store-backed instance, many developers encounter the frustrating "Invalid device name" error during the AMI registration process. This typically occurs when the block device mapping in the manifest file contains device names that EC2 doesn't recognize.
From the provided system information, we can see the instance has the following storage configuration:
[root@ip-172-29-1-29 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 500G 0 part /
xvdb 202:16 0 745.2G 0 disk
└─xvdb1 202:17 0 745.2G 0 part /media/ephemeral0
xvdc 202:32 0 745.2G 0 disk
└─xvdc1 202:33 0 745.2G 0 part /media/ephemeral1
The key issue lies in how device names are specified in the manifest file. The current manifest shows:
<mapping>
<virtual>root</virtual>
<device>/dev/xvda1</device>
</mapping>
This is incorrect because AWS expects different naming conventions in the manifest compared to what you see in the operating system.
For instance store-backed AMIs, you should use the following format:
<mapping>
<virtual>root</virtual>
<device>sda1</device>
</mapping>
Notice three important differences:
1. No "/dev/" prefix
2. Use "sda" instead of "xvda"
3. Keep the partition number (1 in this case)
Here's how your corrected machine_configuration should look:
<machine_configuration>
<architecture>x86_64</architecture>
<block_device_mapping>
<mapping>
<virtual>ami</virtual>
<device>sda</device>
</mapping>
<mapping>
<virtual>ephemeral0</virtual>
<device>sdb</device>
</mapping>
<mapping>
<virtual>ephemeral1</virtual>
<device>sdc</device>
</mapping>
<mapping>
<virtual>root</virtual>
<device>sda1</device>
</mapping>
</block_device_mapping>
</machine_configuration>
When using the AWS CLI to register the AMI, the command would look like:
aws ec2 register-image \
--name "MyInstanceStoreAMI" \
--description "AMI from instance store" \
--architecture x86_64 \
--root-device-name sda1 \
--block-device-mappings file://block_device_mappings.json
Where block_device_mappings.json contains the corrected device names in JSON format.
After successful registration, verify your AMI's block device mapping:
aws ec2 describe-images --image-ids ami-xxxxxxxx --query "Images[0].BlockDeviceMappings"