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.
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):
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.
- 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.
- 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.
- 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.
- 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):
- The Ultimate Guide to AWS Commitments: comprehensive analysis of Savings Plans and Reserved Instances, how they are applied across your organization, and how to use them.
- Savings Plan VS Reserved Instances: The Complete Guide: how to choose and managing your AWS commitments for the best price.
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):
- Best practices for maximizing savings and stability with Spot: an article written in collaboration with the AWS Spot team explaining how to leverage Spot effectively
- Mastering Spot in EKS: Spot Refresh, PDBs, and best practices
- Common Spot Myths, Unexpected Spot Facts, and The Truth About Spot Terminations— there are a lot of misconceptions about Spot; find out if any are surprising to you.
Consider the AWS Enterprise Discount Program (EDP)
Related resource(s) on AWS EDP:
EC2 Cost Optimization Strategies & Best Practices
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):
- Definitive Guide to EC2 Rightsizing: With step-by-step guides, metrics, and best practices
- Essential guide to ASG rightsizing: Rightsizing a single EC2 instance is one thing — everything gets much more complicated if you want to rightsize within Auto Scaling Groups. Tackle this advanced-level strategy with this practical guide.
Stop idle EC2 instances
Related resource(s):
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!