【问题标题】:Resizing an EC2 instance using boto3 [closed]使用 boto3 调整 EC2 实例的大小 [关闭]
【发布时间】:2016-12-04 11:54:41
【问题描述】:

我正在编写一个 Python 2.7 脚本,它将停止 EC2 实例,调整实例大小,然后重新启动实例。有没有办法使用 boto3 来调整实例的大小?如果没有,是否有另一种方法来以编程方式处理实例调整大小?

【问题讨论】:

  • resize是指更改实例类型还是更改EBS卷大小?
  • @KarenB 我应该澄清一下,我的意思是更改实例类型。
  • @error2007s 我已经看过那篇文章,我想我应该在我的文章中提到它。但是没有帮助:问题中的代码是伪代码,答案是关于更改实例类型的一般过程,与boto3无关。

标签: python python-2.7 amazon-web-services amazon-ec2 boto3


【解决方案1】:

这似乎有效:

import boto3

client = boto3.client('ec2')

# Insert your Instance ID here
my_instance = 'i-xxxxxxxx'

# Stop the instance
client.stop_instances(InstanceIds=[my_instance])
waiter=client.get_waiter('instance_stopped')
waiter.wait(InstanceIds=[my_instance])

# Change the instance type
client.modify_instance_attribute(InstanceId=my_instance, Attribute='instanceType', Value='m3.xlarge')

# Start the instance
client.start_instances(InstanceIds=[my_instance])

【讨论】:

  • 这里的服务员代表什么。我也是 aws buto3 的新手,正在尝试调整实例的大小和类型
  • @user3713336 来自Waiter.InstanceStopped documentation每 15 秒轮询一次EC2.Client.describe_instances(),直到达到成功状态。检查失败 40 次后返回错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 2021-05-17
  • 1970-01-01
相关资源
最近更新 更多