【发布时间】:2017-01-27 19:28:31
【问题描述】:
我有一个使用 boto3 库的 Python 2 脚本。
基本上,我有一个实例 ID 列表,我需要对其进行迭代,将每个实例的类型从 c4.xlarge 更改为 t2.micro。
为了完成该任务,我调用了modify_instance_attribute 方法。
我不知道为什么,但我的脚本挂起并显示以下错误消息:
您请求的配置不支持 EBS 优化实例。
这是我的一般情况:
假设我有一段像下面这样的代码:
def change_instance_type(instance_id):
client = boto3.client('ec2')
response = client.modify_instance_attribute(
InstanceId=instance_id,
InstanceType={
'Value': 't2.micro'
}
)
所以,如果我这样执行:
change_instance_type('id-929102')
一切正常。
但是,很奇怪,如果我在如下的 for 循环中执行它
instances_list = ['id-929102']
for instance_id in instances_list:
change_instance_type(instance_id)
我收到上面的错误消息(即,您请求的配置不支持 EBS 优化实例)并且我的脚本死了。
知道为什么会这样吗?
【问题讨论】:
标签: python amazon-web-services amazon-ec2 cloud boto3