What is the best way to change an instance type that is behind an AWS EC2 load balancer?
Example: change from m3.medium to t2.small.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
if you are using auto-scaling group, just change the launch configuration and kill the load-balanced VMs one by one (wait for the killed machine to be replaced before actually killing all machines)
if you are only using load balancer, change the instance type manually (same as above, one by one). you can change the instance type by right-clicking the instance > instance settings > change instance type (your instance has to be stopped to do so).
Please note that you have some limitations when resizing an instance
By far the fastest way to change an instance type is to write a little script containing AWS CLI commands to stop the instance, change the instance type, and start the instance again.
Replace $instance_id and $instance_type with the correct values and do as follows:
aws ec2 stop-instances --instance-ids $instance_id aws ec2 modify-instance-attribute --instance-id $instance_id --instance-type $instance_type aws ec2 start-instances --instance-ids $instance_id
You do need to wait for the instance state to change to stopped before changing the type. I wrote this script to handle all of this for me (also takes a snapshot of the stopped instance):