使用 boto3 调整 EC2 实例的大小
Resizing an EC2 instance using 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 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])