1

I am using boto, the code like this:

dev_xvdb = boto.ec2.blockdevicemapping.EBSBlockDeviceType(volume_id='vol-xxxxxx')
bdm = boto.ec2.blockdevicemapping.BlockDeviceMapping()
bdm['/dev/xvdb'] = dev_xvdb

rs = ec2.request_spot_instances(price=MY_MAX_PRICE,
                                image_id='ami-xxxxx',
                                count=1,
                                type='one-time',
                                key_name='MY_KEY_NAME',
                                security_groups=['default'],
                                instance_type='t1.micro',
                                block_device_map=bdm)

This code can be run properly, but can't attach the EBS volume(id=vol-xxxxxx). Why?

Mike.G
  • 87
  • 3
  • 9

1 Answers1

3

I think the problem here is that you cannot attach an existing volume to an instance with BlockDeviceMapping. The BlockDeviceMapping allows you to specify either a volume size or a snapshot-id. If you specify a size, it will create a new, blank volume of that size and attach it to the device you specify. If you specify a snapshot-id, it will create a new volume from that snapshot and attach it.

If you want to attach an existing volume to an instance you have to use the attach_volume method which can only be run after you have an instance ID.

Why then, you might ask, does boto's EBSBlockDeviceType have a volume_id attribute? That's because when we do a get_all_instances call, the data returned by AWS for BlockDeviceMapping includes the volume_id for currently connected EBS volumes.

garnaat
  • 44,310
  • 7
  • 123
  • 103