Changing EC2 instance type

2024.03.19

Introduction

Changing the EC2 Instance type may become necessary in various cases depending on your workloads and requirements. Here are a few scenarios, where resizing can be beneficial for optimizing cost and performance.

  1. Under-utilized Instances: If your current instance size is too large for your workload, resulting in under-utilization, downsizing to a smaller instance type can result in cost reduction.
  2. Over-utilized Instances: Conversely, if your current instance size is too small for your workload, resulting in over-utilization, upgrading to a larger instance can improve performance.
  3. Modernization: Upgrading from a previous generation to a current generation instance type allows you to take advantage of newer features, like improved performance, lower costs, and additional features.

You can use the AWS Compute Optimizer and Billing and Cost Management to find rightsizing recommendations.

 

Changing instance type from the AWS Management Console

The process of changing the instance type is as follows:

Stop the instance → Change the instance type → Start the instance.

Stop the Instance

  • Sign in to the AWS Management Console and navigate to the EC2 Console.
  • Select the instance for which you want to change the instance type, choose Instance state, and then Stop instance. 
  • When the instance state changes to 'stopped', you can begin changing the instance type. You will not be able to change the instance type if the instance state is not in a stopped state. Please note that it might take a few minutes for the instance to stop.

 

Change Instance Type

  • Select the instance, choose Actions → Instance settings →Change instance type

 

  • Select the New instance type you wish to change to and click Apply. The instance type will be changed immediately.

 

Start the Instance

  • Select the instance, choose the Instance state, and then Start instance. It might take a few minutes for the instance to start.

 

Changing instance type using AWS CLI

Use the following commands to change the instance type of an EC2 Instance using AWS CLI.

Stop the Instance

  • Specify the instance ID in the command.
% aws ec2 stop-instances --instance-ids i-000000000000 --region us-east-1          
{
    "StoppingInstances": [
        {
            "CurrentState": {
                "Code": 64,
                "Name": "stopping"
            },
            "InstanceId": "i-000000000000",
            "PreviousState": {
                "Code": 16,
                "Name": "running"
            }
        }
    ]
}

 

Change Instance Type

  • Specify the instance ID and the new instance type you wish to change to in the command.
% aws ec2 modify-instance-attribute --instance-id i-000000000000 --instance-type "{\"Value\": \"t2.micro\"}" --region us-east-1

 

Start the Instance

  • Specify the instance ID in the command.
% aws ec2 start-instances --instance-ids i-000000000000 --region us-east-1        
{
    "StartingInstances": [
        {
            "CurrentState": {
                "Code": 0,
                "Name": "pending"
            },
            "InstanceId": "i-000000000000",
            "PreviousState": {
                "Code": 80,
                "Name": "stopped"
            }
        }
    ]
}

Reference

Refer to the following document for information on considerations when changing the instance type.

Considerations for compatible instance types

Tips for Right-Sizing

Change the instance type