Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing an EC2 instance using boto3 [closed]

I am writing a Python 2.7 script that will stop an EC2 instance, resize the instance, then start the instance back up. Is there a way to use boto3 to resize an instance? If not, is there another way to handle instance resizing programmatically?

like image 295
danielhklein Avatar asked Jul 29 '16 17:07

danielhklein


1 Answers

This seems to work:

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])
like image 86
John Rotenstein Avatar answered Oct 05 '22 11:10

John Rotenstein