How to Upgrade or Resize a Running EC2 Instance

AWS Logo

You are free to upgrade or downgrade your on-demand EC2 instances as you please. If your instance is struggling to handle your workload, upgrading to a higher tier or another instance class can help your applications run smoother.

Consider Using Auto Scaling, or a Load Balancer

Before upgrading, it’s worth considering whether you really need to. For example, if you’re running a web application, it’s pretty typical for traffic to climb throughout the day and dip down at night when there’s little to no usage. If your instance is only being stressed during peak usage, you’ll essentially be paying double what you need to during the 20 other hours that it was previously handling just fine.

The solution to this is Auto-Scaling, one of the many benefits of AWS’s elastic nature. When CPU or memory usage gets too high on your primary instance, AWS will automatically start a new instance to help handle the additional traffic. Auto-Scaling is heavily encouraged by AWS, as it saves both you and AWS a lot of money. You can read our guide to setting it up to learn more.

This is made possible using a Load Balancer, a network device that evenly distributes traffic across all servers in the auto-scaling group. You don’t have to use auto-scaling to make use of a load balancer though, as they’re commonly used to enable greater redundancy.

If you have reserved instances, you won’t be able to switch tiers, and running two or more instances is your only option. If you have convertible reserved instances however, you are able to exchange them for different instances.

Upgrading an EC2 Instance (with Minimal Downtime)

You can easily switch an instance’s type from the EC2 console. However, you can’t change an instance’s tier while it is running—you’ll need to turn it off.

If turning the instance off isn’t a problem, the first and simplest method is just to accept that you’ll have a few minutes of downtime while the instance restarts, and perform the upgrade at night when traffic is low. If you have multiple instances behind a load balancer, you can upgrade each one one at a time, allowing your application to stay online.

To switch instance types, stop the instance from the EC2 Management Console by right-clicking on it in the list and selecting Instance State > Stop:

Stop instance from EC2 Management Console

Once it’s fully stopped, you can then select Instance Settings > Change Instance Type:

Select Instance Settings > Change Instance Type

This will bring up a dialog where you’ll choose the new instance type.

Choose new instance type

After this, select Instance State > Start to turn the instance back on.

Upgrading an EC2 Instance with Zero Downtime

The best way to achieve a zero-downtime upgrade is with a blue/green deployment. This involves creating a new instance of the desired tier, readying it for production, swapping traffic over to it, then terminating the old instance.

If you don’t have a build script or custom AMI set up though, creating a new instance can take a bit of time. One method to do this quickly is to create an image of your running instance, and launch a new instance using that image. You can create images of running instances by right-clicking them and selecting Image > Create Image:

Create images of running instances

Then, under AMIs in the sidebar, you can launch a new instance using that image.

Once the instance is up and running, the easiest way to swap traffic over is to change the association on your elastic IP address. Click on “Elastic IP” in the sidebar, and select “Associate Elastic IP Address” from the action menu.

Change association on elastic IP address

Select the new instance from the list, and click “Associate:”

Select the new instance

This will swap the EIP over with zero downtime. Once it’s swapped, and the old instance isn’t receiving any traffic, you can terminate the old instance.

Original Article