Change AWS EC2 Instance Type
Why Do We Change EC2 Instance Type?
As your needs change, you might find that your instance is over-utilized (the instance type is too small) or under-utilized (the instance type is too large).
If this is the case, you can change the size of your instance. For example, if your t2.small instance is too small for its workload, you can change it to another instance type that is appropriate for the workload.
You might also want to migrate from a previous generation instance type to a current generation instance type to take advantage of some features.
If the root device for your instance is an EBS volume, you can change the size of the instance simply by changing its instance type, which is known as resizing it
- Virtualization Type: Linux AMIs use one of two types of virtualization: paravirtual (PV) or hardware virtual machine (HVM).You can’t resize an instance that was launched from a PV AMI to an instance type that is HVM only.
- Architecture: AMIs are specific to the architecture of the processor, so you must select an instance type with the same processor architecture as the current instance type.
- Network: Newer instance types must be launched in a VPC. Therefore, you can’t resize an instance in the EC2-Classic platform to a instance type that is available only in a VPC unless you have a nondefault VPC.
- Take the snapshot of the exiting EBS volume.
- Perform this operation during Non-Production hours to avoid downtime.
This article walks you through the process of changing the instance type to meet the requirements.
Resize EBS Backed Instance:
You must stop your Amazon EBS–backed instance before you can change its instance type. When you stop and start an instance,
- It will move the EC2 instance to another host , But the Instance ID will remain the same.
- Public IP address of the instance will be changed, So it is adviced to attach EIP to the instance.
- If your instance is in an Auto Scaling group, the Auto Scaling service marks the stopped instance as unhealthy, and may terminate it and launch a replacement instance. To prevent this, you can suspend the scaling processes for the group while you’re resizing your instance.
- If your instance is in a cluster placement group and, after changing the instance type, the instance start fails, To fix it: Stop all the instances in the cluster placement group, change the instance type for the affected instance, and then restart all the instances in the cluster placement group.
Now In order to change the EC2 instance type , Login to EC2 console,
First we need to stop the instance , To do so , Select the instance ,
Under Actions , Instance state , Stop.
Now the Instance should be in stopped state. Lets go ahead and change the instance type.
Select the Instance , Under Actions , Instance settings , Change Instance Type,
In the Next step , Change the instance type based on the vCPU and Memory ,
Click Apply. To start the instance , Select the instance , Under Actions ,
Instance state , Start.
You should see your instance type is changed under the Instance Description.
Migrating Instance-Store Backed Instance:
- When changing the instance-store backed instance with a different instance type, you must migrate it by creating an image from your instance, and then launching a new instance from this image with the instance type that you need.
- To ensure that your users can continue to use the applications that you’re hosting on your instance uninterrupted, you must take any Elastic IP address that you’ve associated with your original instance and associate it with the new instance. Then you can terminate the original instance.
Lets start migrating the Instance-store backed EC2 instance to new instance type,
- Backup all the data of the Instance-store volume to EBS backed volume or create a snapshot of the volume to avoid loss of data.
- Create an AMI from the Instance-store backed EC2 instance.
- Make sure you launch the new instance in the same VPC and change the instance type.
- Once the instance is created, Remove and attach the volume from Old instance to New instance.You can also use the backup to verify the files.
- You can now setup the applications in the new instance.
- Dont forget to attach the Elastic IP to the New instance from the Old instance , If used.
- Once you verify and everything is working properly , Go ahead and deleted the old instance.
Hope you have learnt to migrate the EC2 instance of EBS backed and Instance-stored Backed to different Instance Types.
Thanks for reading this article.
Please do checkout my other publications.