AWS change instance type - From Console or AWS CLI

How to Change AWS Instance Type or EC2 instance type is more interesting and frequently asked question by many AWS Professionals.

We create EC2 instances as t2, t3.micro but soon we realize that our requirements just got bigger for good and we need more CPU and RAM on our instance. So there comes a question

How to change AWS EC2 instance type?

How to add more CPU into my EC2 instance?

How to add more RAM or Physical Memory to EC2 instance?

How to Ramp-up the System resources in EC2?

Sometimes we think it is so hard and we just abandon the undervalued instance after creating a clone of that instance with different and desired instance type.

But there is an efficient and easiest way and this article is going to talk about it in detail.

 

So How to Change AWS EC2 Instance Type? 

Before we go in there, I need you to give you some quick caveats (or) a kind of prerequisites.

  • Changing the Instance Type Needs a Downtime as you have to shut down the ec2 instance
  • If the EC2 instance does not have an Elastic IP assigned, The Public IP would change on a restart.
  • No Configuration changes are needed to be done within the EC2 server. You can either use AWS CLI or Management Console
  • No new instance would be created. the Same instance would be modified in place

 

Method 1: Changing AWS instance type from AWS Console.

Log in to the AWS Management Console and go to EC2 Dashboard and Choose the instance that you are going to upgrade.

 

Step1: Stop the instance

Once Decided, Select the instance that you are going to upgrade by selecting the checkbox near to it and stop it by clicking on Actions -> Instance State -> Stop

AWS change instance type

 

Step2:  Change the instance Settings and Instance type

As you have stopped the instance of your choice, now select the same instance and go to Actions ->  Instance Settings -> Change Instance Type

This option would be hidden when the instance is in a running state.

AWS change instance type

Step3:  Choose the new instance type

As you complete the step2, you would be presented with a small modal box with a dropdown, where you have to choose the new instance type of your choice.

In my case, I am upgrading my t2.micro instance to t2.medium and I have to choose t2.medium here and Click on Apply

AWS change instance type

 

Step4:  Verify the Change

As you have changed the instance type, You would be able to see the change reflecting immediately in the console on the Description tab

Refer to the following picture and the highlighted areas.

AWS change instance type

 

 

Step5: Start the instance

After verifying that the instance type is changed and verified it is exactly what you wanted to achieve. Go ahead and start the server.

 During all these steps, If you notice closely, You can see the instance_id is never changed.

AWS change instance type

Now you have successfully upgraded the server.

 

What did we achieve

EC2 change instance type

As the following diagram illustrates, you have also increased the CPU core (1 to 2 ) and Physical Memory (1 to 4gb) of the EC2 instance.

So now you know how to change aws instance type (or)  add more CPU or RAM/Physical Memory to the EC2 instance.

 

 

Now to the second method of how to perform aws change instance type (or) ec2 change instance type.

Method 2: Changing AWS instance type using AWS CLI

Make sure you have AWS CLI installed and configured. These are the simple three steps process to do the same

  1. Download AWS CLI
  2. Create API Key from IAM on the Management Console
  3. Enter the AWS Secret key and access key id to the aws configure data

Here is the quick screenshot of my screen while configuring AWS CLI.  If you need assistance refer to this article

EC2 change instance type

I presume that you have a working setup of AWS CLI now on your desktop (mac/windows)

Now let us move on to the actual steps.

 

Step1: Get the instance ID of your Desired instance

To get the instance ID of the instance of your choice. You can simply login to AWS Management console (or) you can use AWS CLI commands to list the instances.

To know more about how to use AWS CLI to list the instances, read this article

If you look at the below screenshot, I have used AWS CLI commands to list the running instances on my AWS account. Since I have only one server running on my AWS. the result is small and I can copy the InstanceID

This is the command I used to list all running instances.

aws ec2 describe-instances \
--query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name,InstanceID:InstanceId}" \ 
--filters Name=instance-state-name,Values=running \
--output table

AWS change instance type

Step2:  Stop the instance

Having the instance ID ready with us, Now let's go ahead and stop the instance using AWS CLI

Here is the AWS CLI command to stop the instance

aws ec2 stop-instances --instance-ids i-0ea05822320404483

Here is the execution output of the AWS CLI stop-instances command

aws change instance type

 

Step3:  Validate if the instance is stopped

To validate if the instance state, Along with the instance-id you can use the following AWS CLI command

aws ec2 describe-instances \
--instance-ids  i-0ea05822320404483 \
--query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name,InstanceID:InstanceId,Instancetype:InstanceType}"  \
--output table

Don't forget to replace the instance-id in the snippet with your actual instance id

EC2 change instance type

 

Step4:  Change the AWS instance type with AWS CLI command

As shown in the previous snap, Our instance is currently in t2.medium type, let us convert it into t2.small

To perform this, we are going to use AWS CLI modify-instance-attribute command

Here is the AWS CLI command to change the aws instance type from t2.medium to t2.small

aws ec2 modify-instance-attribute \
--instance-id i-0ea05822320404483 \
--instance-type "{\"Value\": \"t2.small\"}"

There would be no output for this command !!

If the command is successful, You would not get any output in return. So do not be confused if you are not getting any output after executing this command. That's totally fine.

 

Step5: Validate if the instance type is changed

To validate if the instance type is changed, use the same command you have used on Step3

If you look at the instance type column, you can see that the instance type has been changed from t2.micro to t2.small.

Bingo!!.

aws change instance type

Step6: Start the instance

Now it is time to start the instance using the AWS CLI command line.

here is the command I have used to start the instance

aws ec2 start-instances – instance-ids i-0ea05822320404483

 

The Following snapshot shows the output of AWS CLI start-instances command along with the validation command which we have used on Step3 and Step5.

At the last command, you can see the server has transitioned to running state.

aws change instance type

 

Conclusion

In this article, we have seen how to Change the instance type from Management console as well as AWS CLI command line. We have also learnt how to stop, start, list the instances with AWS CLI commands.

Hope this helps.

Share this article with your friends if you find it worth.

Cheers
Sarav AK

Follow me on Linkedin My Profile
Follow DevopsJunction onFacebook orTwitter
For more practical videos and tutorials. Subscribe to our channel

Buy Me a Coffee at ko-fi.com

Signup for Exclusive "Subscriber-only" Content

Loading