2

I have two related questions - or problems - with the Amazon ec2 API. While I really want to use python and the boto package and that's how I present the code below, I get exactly the same results with the equivalent shell ec2-* commands.

First, I want to spawn an instance from a Debian based public AMI image, but I want a larger root "partition" (because I want to install extra Debian packages which are not in the image). The documentation led me to believe I should do something like this:

import boto.ec2 as BE
import boto.ec2.blockdevicemapping as BEM

conn=BE.connect_to_region('us-east-1')
bdt=BEM.BlockDeviceType()
# I want a 10G root device, not a 1G 
bdt.size=10
bdm=BEM.BlockDeviceMapping()
bdm['/dev/sda1']=bdt
reservations=conn.run_instances('ami-1234abcd', key_name='mykey',
                                instance_type='m1.medium', block_device_map=bdm)

However, this seems to have absolutely no effect. The instance is spawned fine, correct image and everything, but the root device is still just 1G :-(

So, then I thought maybe I need to somehow initialize the BlockDeviceMapping from the image before I modify it. I tried it like this:

bdm=conn.get_image_attribute('ami-1234abcd', attribute='blockDeviceMapping')

and this results in some strange exception trace saying 'Attempted unauthorized operation' or similar. And this happens even for an image that I myself created by freezing another instance!

It is easy enough to modify the device configuration when creating an instance in the horrible web interface. Please show me how to do so programatically! Thanks.

4

1 回答 1

0

您的代码看起来正确。

尝试使用相同的代码来启动一个 Ubuntu AMI(你可以在这里找到它们:http: //cloud-images.ubuntu.com/locator/ec2/

当 Ubuntu AMI 启动时,它将查看根块设备。如果设备大于根文件系统,它将自动调整根文件系统的大小以填充根块设备。不用大惊小怪 - 其他一切都一样。

这几乎总是你想要发生的事情。

如果它适用于 Ubuntu,至少你知道你的代码是正确的。然后你只需要弄清楚如何调整 Debian rootfs 的大小(或者只使用 Ubuntu)。

于 2013-07-17T02:04:40.317 回答