如何使用 Boto 启动 EC2 实例,指定 EBS 的大小? [英] How to launch EC2 instance with Boto, specifying size of EBS?

查看:28
本文介绍了如何使用 Boto 启动 EC2 实例,指定 EBS 的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 boto/python 启动一个从 EBS 卷启动的新 EC2 实例.在我启动实例时,我想覆盖启动 EBS 卷的默认大小.

I'm using boto/python to launch a new EC2 instance that boots from an EBS volume. At the time I launch the instance, I'd like to override the default size of the booting EBS volume.

我发现没有适合我的启动代码的 boto 方法或参数:

I found no boto methods or parameters that might fit into my launch code:

ec2 = boto.connect_ec2( ACCESS_KEY, SECRET_KEY, region=region )

reservation = ec2.run_instances( image_id=AMI_ID, 
                                 key_name=EC2_KEY_HANDLE, 
                                 instance_type=INSTANCE_TYPE,
                                 security_groups = [ SECGROUP_HANDLE, ] )

此网页展示了如何增加使用命令行工具运行 EC2 实例的 EBS 卷,但我想在指定 EC2 实例时使用 boto:

This web page shows how to increase the size of a running EC2-instance's EBS volume using command-line tools, but I'd like to use boto at the time the EC2 instance is specified:

推荐答案

你必须先创建一个块设备映射:

You have to create a block device mapping first:

dev_sda1 = boto.ec2.blockdevicemapping.EBSBlockDeviceType()
dev_sda1.size = 50 # size in Gigabytes
bdm = boto.ec2.blockdevicemapping.BlockDeviceMapping()
bdm['/dev/sda1'] = dev_sda1 

此后,您可以在 run_instances 调用中提供块设备映射:

After this you can give the block device map in your run_instances call:

reservation = ec2.run_instances( image_id=AMI_ID, 
                                 key_name=EC2_KEY_HANDLE, 
                                 instance_type=INSTANCE_TYPE,
                                 security_groups = [ SECGROUP_HANDLE, ],
                                 block_device_mappings = [bdm])

不幸的是,这是没有很好的记录,但是示例可以在源代码中找到.

Unfortunately this is not really well documented, but the example can be found in the source code.

这篇关于如何使用 Boto 启动 EC2 实例,指定 EBS 的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆