Elastic Compute Cloud (EC2) instances are the flexible, scalable building blocks of your AWS compute. As the cornerstone of AWS services, they have a fundamental impact on your cost optimization efforts.

This comprehensive guide covers everything you need to know about cost-optimizing your EC2 usage to do more in the cloud while spending less. That includes selecting the right instance, choosing the best pricing option, and optimizing autoscaling, rightsizing and stopping idle instances to align spend with actual demand.

The Basics: Choosing the Right EC2 Instance Type

AWS currently offers more than 750 instance types, and choosing the right one has a significant impact on development and budgeting.

Amazon EC2 instance families are distributed in groups that are optimized for the following workloads: general-purpose computing, compute-optimized tasks, memory-intensive applications, storage-intensive workloads and GPU accelerated computing.

A diagram showing various instance types available on Amazon Web Services (AWS). The instance types are categorized into General Purpose, Compute Optimized, Memory Optimized, Storage Optimized, and Accelerated Computing. Each category lists different instance families and their corresponding codes.

Certain instances are specifically built for cost-effectiveness.

  • Graviton-based instances: carbon-efficient and offer up to 40% more price-performance than non-Graviton instances. However, your workload must be properly architected (i.e. applications must be designed to run on ARM architecture).
  • EC2 Flex instances: great for workloads that don’t use all of their resources
  • Accelerated Computing instances: specifically for ML/AI workloads, deliver up to 50% more price-performance for training models

Choosing the right instance type includes (1) understanding your application’s requirements, (2) selecting an appropriate instance family that optimizes for the right metrics, and (3) selecting the right instance type and size specific to your workload that considers both cost and performance.

Related resource(s):

The full guide How to Choose EC2 Instances includes step by step, practical tips, and the best tools to use to choose instances optimally suited to your workloads.

EC2 Instance Pricing

AWS offers four main models you can mix and match to best suit your needs. Finding the right balance is critical for maximizing your cost savings.

  1. On-Demand:The traditional option, where users pay only for what they use without long-term commitments. It’s the easiest to use, but also the costliest.
  2. Reserved Instances: If you have long-running predictable workloads, Reserved Instance commitments offer discounts in exchange for 1 or 3-year commitments. You can pay fully or partially upfront for additional savings.
  3. Savings Plans:AWS (and we) generally recommend Savings Plans over Reserved Instances, because they offer similar savings with more flexibility to accommodate your dynamic usage. And, discounts are applied automatically across all components, potentially reducing time and overhead spent on resource management.
  4. Spot Instances:Spot Instances are available at a discount of up to 90%, but the catch is that AWS can reclaim these instances with just two minutes’ notice.

More about Savings Plans

Savings Plans provide a flexible pricing model offering lower prices than On-Demand pricing in exchange for a specific usage commitment (measured in $/hour) for a one- or three-year period.

Compute Savings Plans are the most flexible commitment option. They allow you to apply usage across Amazon EC2, (regardless of instance family, size, AZ, region, OS, or tenancy), AWS Lambda, and AWS Fargate.

For example, you could change a c4.large instance in Ireland to an t4g.16xl instance in London and still receive the Savings Plan discount.

EC2 Instance Savings Plans provide the lowest prices, with savings up to 72% (compared to 66% for Compute SP).

However, you need to commit to a specified region and instance family, though you can change instance size, OS, and tenancy.

For a complete comparison of all Savings Plans and Reserved Instances, see this article.

For maximum total discounts, it’s crucial to analyze your usage patterns and combine all four of these pricing models accordingly. Let’s talk about the practical steps to accomplish this.

Managing commitments

As stated, AWS Reserved Instances and Savings Plans offer much lower prices than On-Demand — but forecasting purchase commitments is an art.

In the dynamic world of cloud infrastructure, systems are constantly evolving — your team is constantly modernizing and rightsizing, so the overall cloud cost fluctuates. If you commit too much, you pay for unused capacity. But if you commit too little, you’ll end up paying the higher On-Demand rates on some of your resources.

Related resource(s):

Take advantage of Spot discounts

For the highest discounts it’s key to take advantage of Spot instances, which are excess AWS capacity available for dramatically lower (up to 90% off) prices. However, because AWS can reclaim this excess capacity at any time, they require a little more planning to use.

That being said, AWS has made many changes making it easier to use Spot instances, and automation tools are available to help streamline and simplify the process.

Here are some resources to help you leverage Spot more effectively.

Related resource(s):

A line graph showing the termination percentage of spot instances from October to November 2023. The x-axis represents the days of the month, while the y-axis shows the amount of launched and terminated spot instances, as well as the percentage of terminated instances. The green line represents the amount of launched spot instances, the blue line represents the average percentage of terminated instances, and the orange line represents the amount of terminated spot instances. The graph also includes a vertical line indicating the highest termination percentage of 5.5%.

Consider the AWS Enterprise Discount Program (EDP)

AWS EDP is a savings program for enterprise cloud users with significant AWS cloud usage, typically $1 million per year or more. It offers discounts on total AWS billing, which increase based on total spend and the length of the commitment period, typically 1-5 years.
A line graph showing the relationship between committed tenure and committed annual spending. The x-axis represents the committed tenure in years (1, 2, 3, 4, and 5), and the y-axis represents the committed annual spending in millions of dollars. A blue bar chart is superimposed on the line graph, visually reinforcing the trend. The line graph shows a steady increase in committed annual spending as the committed tenure increases, reaching $50 million at the 5-year mark.
The biggest advantage of an Enterprise Discount Program is that it allows companies with large-scale, high-volume to realize greater cost savings for the AWS services that they are already using across almost all AWS services and regions.

Related resource(s) on AWS EDP:

Find out about the advantages and disadvantages of EDP, strategies and tips for getting the most discounts, and more in the Ultimate Guide to AWS EDP.

EC2 Cost Optimization Strategies & Best Practices

Let’s dive into the concepts and best practices that are key to reducing your EC2 costs.

EC2 Autoscaling

By deploying your applications under an autoscaler like Auto Scaling Groups (ASG), Cluster Autoscaler (CA), or Karpenter, you enable automatic scaling of EC2 instances based on demand. These decisions feed into the autoscalers’ workload level decisions, driving them to adjust resources efficiently and save on costs.

By properly configuring your workloads to work with autoscalers, you (1) maintain performance and ensure sufficient resources, while (2) reducing cost by provisioning only the resources that are actually needed.

Related resource(s):

Pod-level scaling

Horizontal scaling involves adding multiple servers to an existing pool of machines to handle increased load, rather than upgrading the capabilities of an existing machine. In EKS, this is typically done with Horizontal Pod Autoscaler (HPA), which dynamically adjusts the number of pod replicas in a deployment based on observed metrics like CPU or custom metrics.

On the other hand, vertical scaling involves adding additional capabilities (such as processing power, memory or storage) to a single machine, to manage higher loads without adding multiple machines to the system. This is done with Vertical Pod Autoscaler (VPA).

Related resource(s):

Node-level scaling

While HPA and VPA are integral for optimizing resource usage at the pod level, managing the underlying infrastructure’s scalability is crucial for comprehensive resource optimization. Rightsizing nodes in your Kubernetes clusters is crucial for optimizing EC2 costs. Without proper management, clusters can become over-provisioned with underutilized nodes leading to unnecessary expenses.

This is where Cluster Autoscaler and Karpenter, the two most popular EKS node scaling solutions, are integral.

  • Cluster Autoscalerautomatically scales the nodes in your cluster up or down based on resource requests of your pods. It ensures your applications have the resources they need but doesn’t always optimize for cost since it doesn’t adjust instance types or sizes.
  • Karpenteris an open-source solution offering advanced node lifecycle management for EKS. It automatically launches the optimal compute resources to handle your cluster’s workloads. Karpenter intelligently selects the most cost-effective instance types and sizes in real-time, improving node efficiency and reducing costs.

When it comes to node-level scaling and rightsizing, visibility is key — platforms like nOps with features like Business Contexts Plus allow you to gain deeper insights into node efficiency, helping you identify areas for further optimization.

Related resource(s):

EC2 rightsizing

By analyzing historical usage and performance, you can identify and rightsize or eliminate instances that are not consuming all the resources currently available to them. Scaling these resources to their proper level goes a long way toward taming cloud costs.

The key consideration when rightsizing is ensuring you’re collecting the right data. Plenty of rightsizing recommendations are available through AWS-native tools like Trusted Advisor and third-party sources, yet engineers often don’t trust these recommendations or act on them.

Reliable recommendations require granular historical data on memory, utilization, network bandwidth, volume size, and more collected through a tool like CloudWatch or Datadog.

Related resource(s):

Stop idle EC2 instances

Stopping idle instances is one of the most effective cloud optimization strategies. For every dollar saved on an instance, two more dollars are saved on accompanying storage, network and database charges.
A screenshot of a Twitter conversation between Corey Quinn (@QuinnyPig) and Daniel Feldman (@d_feldman). Corey Quinn jokingly says that the most expensive AWS EC2 instance is the one you forget to turn off. Daniel Feldman corrects him by stating that the most expensive AWS instance type is U-24TB1 112xlarge, costing $218 per hour or $157,000 per month. The tweet has 54.3K views, 102 retweets, 9 quotes, 1,419 likes, and 24 bookmarks.

Related resource(s):

Find out how to easily identify and stop idle EC2 instances.

Diversify your EC2 Optimization approach

When optimizing EC2, you should never put all your eggs in one basket — especially when taking advantage of autoscaling. Relying solely on RIs or SPs creates a high chance of underutilization. On the other hand, going 100% with Spot Instances can cause instability and performance issues for your applications and customers.

The industry standard — and our strong recommendation — is to diversify your approach to get the best value.

At nOps, we manage your Reserved Instances, Savings Plans and Spot with AI, continuously ensuring you’re always maximizing the discount on your changing usage. nOps Compute Copilot also optimizes Spot by launching the most appropriate instances and automatically falling back to On-Demand when needed. Balancing RI, SP and Spot for cost and performance is done through automation and requires no effort on your part once configured.

Book a demo to find out how much you can save in just 10 minutes.

Save on EC2 with nOps

If you’re looking to save on your EC2 costs, nOps makes it easy and painless for engineers to take action on cloud optimization.

The nOps all-in-one cloud platform features include:

  • Business Contexts: Understand and allocate 100% of your AWS bill down to the container level
  • Compute Copilot: Intelligent provisioner that helps you save with Spot discounts to reduce On-Demand costs by up to 90%
  • Commitment management: Automatic life-cycle management of your EC2/RDS/EKS commitments with risk-free guarantee
  • Storage migration:One-Click EBS volume migration
  • Rightsizing: Rightsize EC2 instances and Auto Scaling Groups
  • Resource Scheduling: Automatically schedule and pause idle resources

nOps was recently ranked #1 with five stars in G2’s cloud cost management category, and we optimize $1.5+ billion in cloud spend for our customers.

Join our customers using nOps to understand your cloud costs and leverage automation with complete confidence by booking a demo today!