I would like to launch an EC2 instance using the python boto library, with a previously created EBS volume attached (in addition to the root volume).
After connecting, I look up the volume by its name tag, and try to create a block device list containing the volume. I was getting all kinds of errors, but eventually created the following code which at least succeeds in launching an instance.
volumes=conn.get_all_volumes(filters={'tag:Name':'TestVolume'})
vol=volumes[0]
print repr(vol)
disks=ec2.blockdevicemapping.BlockDeviceMapping()
xvdf=ec2.blockdevicemapping.BlockDeviceType(volume_id=vol.id,
size=vol.size,volume_type=vol.type)
disks['/dev/xvdf']=xvdf
base_image="ami-9a562df2" #ubuntu 14.04
reservation=conn.run_instances(
base_image,
instance_type="t2.micro",
block_device_map=disks)
The print statement shows it was able to lookup the volume and reports the correct volume id. However when the instance launches a new unformatted 32GB volume is created and attached to the volume instead.
I'm having trouble finding documentation that makes this clear. What is the correct way to add a specific EBS Volume to the block_device_map ?