DEV Community

Cover image for How to choose the right EC2 Instance for your application
jameslaneovermind
jameslaneovermind

Posted on

How to choose the right EC2 Instance for your application

TLDR: With over 400 instances to choose from its not easy. These 6 things will help make narrowing down your decision that bit easier.

As a DevOps engineer working with AWS, selecting the right Elastic Compute Cloud (EC2) instance type can be a daunting task given the almost 400 options available. Nevertheless, there are several things you can do to simplify the process and optimise costs while delivering high performance. Making careful choices when it comes to EC2 instances is crucial, as compute often constitutes the bulk of cloud bills. By optimising this aspect, you could potentially achieve significant reductions in your cloud costs.


AWS has a great video on their youtube filmed at reInvent:2021 that talks you through in detail selecting and optimising instances. However I've summarised some of the top 6 below. Adopting this will help you when it comes to selecting your next instance.

The top 6 things to consider when making a decision

1. Identify your application requirements

Determine the workload's minimum requirements to avoid over-provisioning or running memory-intensive applications on underpowered instances. Choose an EC2 instance that satisfies the application's needs, including vCPU count, vCPU architecture, network, memory, and SSD storage.

For example, if you intend to support a machine learning application, choose a GPU-dense instance type instead of a CPU-dense one. In 2021 AWS released EC2 Inf, an instance type designed for inference, which provides higher throughput and a lower cost per inference than EC2 G4 instances.

2. Research EC2 instance types and families

Many EC2 instance families exist, each with its strengths and weaknesses. Conduct a thorough search for the most appropriate family for your workload needs. For example, the C5 family might be the best choice for a high-performance computing (HPC) workload. If you require high network performance, consider the enhanced networking feature on the C5n family.

Remember to have cost savings in mind when selecting an instance size. EC2 instances are available in various sizes, and you should scale your resources to match the workload requirements. However, remember that size is not the only factor affecting cost. AWS deploys different computers to provide compute capacity, each with chips having varying performance characteristics. Benchmarking is a reliable method of determining the most cost-effective instance size.

3. Consider the pros and cons of different pricing mode

AWS offers several pricing models for EC2 instances, including Spot Instances, Reserved Instances, and On-Demand Instances. Each has its advantages and disadvantages, and you should select the one that best meets your workload needs and budget.

On-Demand Instances:
Customers pay for actual usage on an hourly basis, with no long-term commitments or upfront payments required. Advantages include flexibility, scalability, and the ability to pay only for what you use. However, it can be more expensive for long-running instances.

Reserved Instances:
Customers receive a significant discount on the hourly rate in exchange for committing to using a specific instance type for one or three years. This pricing model is advantageous for stable workloads that run continuously and offer cost savings over the long term. However, it can be inflexible.

Spot Instances:
Customers can bid on unused EC2 capacity, with prices fluctuating based on supply and demand. This pricing model offers potential cost savings, but the availability of Spot Instances can be unpredictable. AWS can also terminate instances with two minutes' notice when the spot price exceeds the customer's bid.

4. Be mindful with your storage selection

When selecting an EC2 instance in AWS, consider factors such as performance, durability, cost, storage type, and storage size. AWS has two types of storage: block and object. Block storage is for consistent and low-latency performance. AWS has Elastic Block Store (EBS) for persistent block storage, and instance store for temporary block storage. Object storage is for scalable and durable storage. AWS has Simple Storage Service (S3) for highly durable and scalable storage, and Amazon Glacier for low-cost storage.

5. Use Spot Instances (even for production workloads)

Spot Instances are unused EC2 instances available at a lower price than on-Demand instances. Although they may be interrupted if the demand for EC2 instances rises, they can be an excellent option for production workloads with flexible timing.

Explained: What are Spot instances?
Spot Instances are a cost-effective way to run your applications because you can bid on unused instances. The price is lower than the on-demand price and varies based on supply and demand.

6. Automate everything

To improve your system's efficiency and consistency, simplify the selection and deployment of EC2 instances. Use automation tools like Amazon Elastic Container Service (ECS) and Lambda. These tools automate the entire process from instance selection to ongoing monitoring. By automating, you can save time and effort while ensuring peak performance and avoiding human error.

In summary, selecting the optimal EC2 instance type may seem intimidating given the vast number of options available. Still, by following the above steps and taking into account factors such as cost optimisation, storage selection, and pricing models, you can make an informed decision.

Top comments (0)