There are a number of reasons why you may wish to change an EC2 instance running in AWS.
In this post, Karl covers the pre-requisites for changing AWS EC2 instance types, about EBS and store backed instances, and how to choose the best instance type for your requirements. Or, you can go straight to the step-by-step guide to upgrade or resize your EC2 instance type.
AWS Cloud & EC2 Instance Types
EC2, or Elastic Compute Cloud, is Amazon Web Services IaaS (Infrastructure as a Service) offering – essentially it is a service for running virtual machines in the AWS cloud, where developers can upgrade or change their specification, or ‘instance type’, according to current usage.
With over 275 instance configurations – based on CPU, RAM, storage type and network performance – users need to evaluate their important metrics and monitor performance of the instance specification to ensure best efficiency.
Want to know more about EC2 and all the different instance types? Read this article first: AWS EC2 – Everything You Need To Know About EC2 Instances
Why Change EC2 instance type?
Here are some of the most common reasons to change instance type:
- Increase resources – perhaps you need more CPU, RAM or network throughput due to increased application demand, which hopefully is a good thing!
- Decrease resources – perhaps you want to rightsize for cost optimization purposes by removing any underutilized resources.
- Change of workload type – if the workload on the EC2 instance has changed from, say, CPU instensive to RAM intensive, it may be more efficient to change to a different instance family more suited to the new workload.
- Migrate from previous generation to current generation instance type – AWS frequently update their instance families, and often newer generation instances offer higher performance at a lower cost.
If you decide that you need to change instance type for performance or cost management reasons, you can simply resize it to another instance type as long as:
- Virtualization type is the same – PV (paravirtual) or HVM (Hardware virtual machine) – EC2 uses both virtualization types and it is not possible to change an instance from one type to the other.
- CPU Architecture is the same – there is limited support for 32 bit AMIs, Arm processors etc – you cannot switch from an Intel CPU instance to an AMD CPU instance, for example.
- Network is compatible – newer instances need to be in a VPC, so EC2 classic instances can’t be resized to a newer instance type if not in a VPC.
- Root Storage is an EBS volume – if your root volume is instance store based (on ephemeral storage), you’ll need to migrate your application to the new instance type.
- Enhanced Networking Drivers are installed – if the new instance type supports advanced networking features, you’ll need to install the drivers before re-sizing.
- NVMe Drivers are installed – for instances that support NVMe (Non-Volatile Memory Express) SSD instance store volumes.
How to upgrade or resize EBS backed EC2 instance
If the EC2 instance you want to change has an EBS (Elastic Block Store) root partition, you can simply change or ‘resize’ the instance. The instance type that you want to resize to must be compatible with the current instance type, otherwise you will need to create a new instance and migrate your apps and data to the new instance (see next section for details on how to do this).
In order to resize an EBS backed instance you must first stop the instance. When stopping or starting an EC2 instance you need to be aware that:
- The instance will be moved to new hardware, but the instance ID will not change.
- The instance will retain any associated Elastic IP Addresses, private IPv4 and any IPv6 addresses, but if it has a public IPv4 address this will change.
- If the instance is part of an Auto Scaling group, you may wish to disable the scaling processes while resizing the instance, to prevent it from being terminated due to being marked as ‘unhealthy’.
- You should plan for downtime when the instance is stopped – you may need to schedule a maintenance window as the process can take several minutes, plus you should plan for any unforeseen problems.
Follow these steps to resize your EC2 instance in the AWS Console:
- Install any drivers required by the new instance type onto the current instance (NVMe drivers, enhanced networking drivers)
- Open the EC2 console and choose instances from the navigation pane:
- Select the instance and then select ‘Actions, State, Stop’:
- Choose ‘Yes Stop’ in the dialogue box:
- Ensuring that the instance is still selected, choose ‘Actions, Instance, Settings, Change
- In the dialogue box that appears, there isa drop down menu that will only display compatible instance types – if the instance type you want is not displayed, you cannot resize to this instance type. If the instance type you are switching to supports EBS-optimization, you can select it in the check box to enable:
- Restart the stopped instance by selecting ‘Actions, Instance State, Start’, then choose ‘Yes Start’ in the dialogue box that appears. The instance can take a few minutes to reach the ‘running’ state.
How to change Instance Store backed EC2 Instance Type
The process is a little more complicated if you want to change the instance type of an Instance Store backed EC2 instance type.
It is not possible to simply change the instance type – you must migrate to a new instance type by creating an image of the existing instance and launching a new instance of the desired type from the image.
Follow these steps to migrate an instance store backed instance:
- Create a backup of any data on the instance store volumes to persistent storage. For any attached EBS volumes, you can either take a snapshot or detach the volumes from the instance to be reattached to the new instance once created.
- Create an AMI of the instance store backed instance. Follow the instructions here to create an Instance Store backed Linux AMI
- In the EC2 console, find the AMI you just created:
- Select the AMI that you wish to use and choose ‘Launch’:
- Specify the instance type you want in the launch wizard – if you can’t see the instance type you want then it is not compatible with your AMI:
- Terminate the original instance if it is no longer required.
Which EC2 Instance Type Do I need?
If you know you need to change your EC2 instance type, but you are unsure which instance type to select from the dazzling array of almost 300 instance types, fear not, you are in luck.
AWS Compute Optimizer is on hand to provide recommendations to help with improving performance, saving money, or both.
Compute Optimizer analyses existing EC2 instance specifications and utilization metrics. By comparing the data, it will recommend which EC2 instance types are best suited to your workloads.
Compute Optimizer recommendations fall into the following categories:
- Under-provisioned – you may need more CPU, RAM or network throughput so need to upgrade.
- Over-provisioned – you have too much CPU, RAM or network throughput, so you can safely downgrade.
- Optimized – everything is just right
- None – there are no recommendations for the instance, perhaps because there is not enough data, or the instance type is not yet supported by Compute Opitmizer.
Although Compute Optimizer is free to use, you must first opt in to start the collection of data on which the recommendations will be based. It may take up to 12 hours before any data or recommendations are available.
Once Compute Optimizer has made recommendations, you can find them in the EC2 console by selecting and instance, then in the ‘Details’ tab, under ‘Finding’:
The recommendation will display the suggested instance type along with the hourly on-demand price for the recommended instance.
So there you have it. AWS has the tools to help you select the appropriate instance type from a huge list of options. If this all still sounds a little overwhelming, Logicata are here to help. Check out our AWS Managed Services – we’re routinely optimizing EC2 instances for our clients while minimizing downtime, so perhaps we can assist you too!