<分区>
我正在编写一个 Python 2.7 脚本,它将停止 EC2 实例,调整实例大小,然后重新启动实例。有没有办法使用 boto3 调整实例大小?如果没有,是否有另一种方法以编程方式处理实例大小调整?
<分区>
我正在编写一个 Python 2.7 脚本,它将停止 EC2 实例,调整实例大小,然后重新启动实例。有没有办法使用 boto3 调整实例大小?如果没有,是否有另一种方法以编程方式处理实例大小调整?
最佳答案
这似乎可行:
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])
关于python - 使用 boto3 调整 EC2 实例的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38664328/
相关文章:
python - 如何编写一个带有 for 循环的 Lambda
ruby-on-rails - EC2 : Unable to rvm install ruby
amazon-web-services - 如何加载 Sagemaker 中不可用的 python 模块?
ruby-on-rails - 如何解决 "Could not find i18n-0.6.5 in any of the sources (Bundler::GemNotFound)"AWS 部署
python - 在 python 中使用神经网络预测时间序列数据
python - 有没有什么方法可以在字符串之间添加而不将字符串更改为列表 - 或者字符串是不可变的?