Cloud providers sell compute by the hour, but you can get massive discounts by committing to usage ahead of time or by leveraging their spare capacity.

Let’s see how this plays out in practice. Imagine a small web application that needs two t3.medium instances running 24/7.

Scenario: On-Demand Pricing

  • Instance type: t3.medium
  • On-Demand Price: $0.0416 per hour (this will vary slightly by region, this is for us-east-1)
  • Instances: 2
  • Hours per day: 24
  • Days per month: 30 (for simplicity)

Calculation: 2 instances * 24 hours/day * 30 days/month * $0.0416/hour = $59.90 per month

This is the baseline. Now, let’s explore how to slash that bill.

Reserved Instances (RIs): The Long-Term Commitment Discount

Reserved Instances are like signing a long-term lease on your compute. You commit to a specific instance family, region, and usage level for 1 or 3 years, and in return, you get a significant discount compared to on-demand pricing.

How it works:

When you purchase a Reserved Instance, you’re essentially pre-paying for a certain amount of compute capacity. The cloud provider then guarantees that capacity for you. This is beneficial for them because it allows them to better manage their hardware utilization. For you, it means predictable costs and substantial savings.

Types of RIs:

  • Standard RIs: Offer the most flexibility and the largest discounts. You can modify attributes like instance size (within limits) or tenancy.
  • Convertible RIs: Allow you to change instance families, operating systems, or tenancy during the term, but the discount is slightly less than Standard RIs.
  • Scheduled RIs: Designed for workloads with predictable, recurring usage patterns (e.g., running an application only every other weekend). You reserve capacity for specific 24-hour periods.

Purchasing RIs:

Let’s say you decide to commit to those two t3.medium instances for a year.

  • Instance type: t3.medium
  • Term: 1 Year
  • Payment: All Upfront (offers the highest discount)
  • RI Price: $0.0291 per hour (again, us-east-1 example)

Calculation: 2 instances * 24 hours/day * 30 days/month * $0.0291/hour = $41.89 per month

Savings: $59.90 - $41.89 = $18.01 per month, or about 30% off.

If you commit to a 3-year term with an All Upfront payment, the savings can jump to 50-70%.

Key Considerations for RIs:

  • Commitment: You are locked in for the term. If your needs change drastically, you might end up paying for unused capacity.
  • Flexibility: Understand the different RI types and their flexibility options. Convertible RIs can mitigate some risk if your workload might evolve.
  • Regionality: RIs are typically region-specific.
  • Instance Size Flexibility: Standard RIs offer some flexibility to use smaller instances within the same family at no additional charge. For example, a t3.large RI could cover two t3.medium instances.

Spot Instances: The Fire Sale for Fleeting Compute

Spot Instances are a way to bid on AWS’s unused EC2 capacity. The price, known as the Spot Price, fluctuates based on supply and demand. If the Spot Price rises above your bid price, your instance is terminated. This makes them ideal for fault-tolerant, flexible, or non-time-critical workloads.

How it works:

Think of it as an auction. You specify the maximum price you’re willing to pay per hour for a particular instance type. If the current Spot Price is below your maximum, your instance runs. If it goes above, AWS can reclaim the capacity with a two-minute warning.

Example:

Let’s use the same t3.medium instance. The Spot Price might be around $0.015 per hour.

  • Instance type: t3.medium
  • Maximum Bid Price: $0.030 per hour (you’re being generous to ensure it runs)
  • Spot Price: $0.015 per hour (this is what you actually pay)

Calculation: 2 instances * 24 hours/day * 30 days/month * $0.015/hour = $21.60 per month

Savings: $59.90 (on-demand) - $21.60 = $38.30 per month, or about 64% off.

Use Cases for Spot:

  • Batch processing
  • Big data analytics (e.g., Spark, Hadoop)
  • Continuous integration/continuous delivery (CI/CD) pipelines
  • High-performance computing (HPC)
  • Stateless web servers (if architected for high availability and graceful shutdown)

Managing Spot Interruptions:

  • Diversify Instance Types: Request Spot instances across multiple instance types and Availability Zones. This reduces the chance of all your instances being interrupted simultaneously.
  • Handle Termination Notices: Use the EC2 instance metadata service to detect termination notices (a two-minute warning). This allows your application to save its state, checkpoint work, or gracefully shut down.
  • Use Spot Fleets or EC2 Fleet: These services help manage a collection of Spot instances, automatically bidding on capacity and diversifying across instance types and AZs.

Rightsizing: The Art of Not Overpaying for What You Don’t Need

Rightsizing is about ensuring your instances are the correct size for the workload they are running. It’s the simplest and often most overlooked cost-saving strategy. You might be running an instance that’s twice as powerful as it needs to be, simply because it was easier to pick a larger size initially.

How it works:

This involves monitoring your instance’s CPU utilization, memory usage, network traffic, and disk I/O over a period (e.g., 14 days). Tools like AWS Compute Optimizer, CloudWatch, or third-party monitoring solutions can provide these metrics. Once you have a clear picture of your actual resource needs, you can downsize the instance to a smaller, cheaper type that still meets your performance requirements.

Diagnosis:

Let’s say you have a t3.large instance running your web app, and monitoring shows it’s consistently using only 20% of its CPU and 30% of its memory.

  • t3.large On-Demand Price: $0.0832 per hour
  • t3.medium On-Demand Price: $0.0416 per hour

Rightsizing Action:

You decide to downsize from t3.large to t3.medium.

Savings: $0.0832 - $0.0416 = $0.0416 per hour, or about $29.95 per month for a single instance running 24/7.

Tools for Rightsizing:

  • AWS Compute Optimizer: Provides recommendations for instance rightsizing based on historical utilization data.
  • Amazon CloudWatch: Collects and tracks metrics, allowing you to set alarms and analyze historical data for CPU, memory, and network usage.
  • Third-party monitoring tools: Datadog, New Relic, Dynatrace, etc., offer detailed performance metrics and analysis.

The "Gotcha":

When considering rightsizing, ensure you’re looking at average utilization over peak times, not just the absolute peak. A short spike in CPU usage that doesn’t impact performance is not a reason to stick with an oversized instance. However, if your application experiences predictable, regular spikes that exceed the capacity of a smaller instance, you must account for that when rightsizing.

Putting It All Together

For our example web application needing two t3.medium instances:

  • On-Demand: $59.90/month
  • 1-Year RI (Standard, All Upfront): $41.89/month (approx. 30% savings)
  • Spot Instances: $21.60/month (approx. 64% savings, but requires fault tolerance)
  • Rightsizing (if currently on t3.large): Downsizing to t3.medium saves $29.95/month per instance.

By combining these strategies, you can significantly reduce your cloud infrastructure costs. For stable, predictable workloads, RIs offer guaranteed savings. For elastic or fault-tolerant workloads, Spot instances provide the deepest discounts. And rightsizing is a foundational practice for any cost optimization effort.

The next step in cost optimization often involves looking at storage and database services.

Want structured learning?

Take the full DevOps & Platform Engineering course →