Skip to content

Options for decreasing infrastructure costs in AWS

Henrique Pacheco edited this page Jul 29, 2020 · 2 revisions

Options for decreasing infrastructure costs in AWS

When trying to find ways to reduce costs in AWS, there are a couple of options out-of-the-box that can be considered:

  • Using EC2 Spot instances, instead of on-demand instances.
  • Using EC2 Reserved instances, instead of on-demand instances.

Using EC2 Spot instances

A Spot instance is an unused EC2 instance that is available for less than the On-Demand price. The price of each Spot instance type in each Availability Zone is set by Amazon EC2 and adjusted gradually based on the long-term supply of and demand for Spot instances. Spot instances run whenever capacity is available and the maximum price per hour for your request exceeds the Spot price. Spot instances are a cost-effective choice if we can be flexible about when our applications run and if our applications can be interrupted.

Pros and cons

  • Good, because it is the most cost-effective strategy for reducing the costs - the cost of EC2 Spot instances can be up to 90% lower when compared with on-demand instances (however, we should keep in mind that, due to the volatile nature of the Spot instances pricing, the amount that will be saved cannot be accurately predicted).
  • Good, because using spot instances usually does not represent a complex change in the infrastructure - it usually involves doing some changes in the existing configuration, add some extra components to deal with the possible node termination on short notice.
  • Bad, because relying on Spot instances means the infrastructure has to be prepared for the possibility of not having Spot instances available for usage. This can be harmful to the stability and resilience of the infrastructure.

Using EC2 Reserved instances

Reserved instances provide an alternative to on-demand instances that is not subject to the volatility that we can find in Spot instances, but with attractive and measurable savings in costs. Reserved instances can be reserved for a period of 1 or 3 years. Some (or all) of the cost of these instances can be paid upfront, in order to get even higher discounts.

Pros and cons

  • Good, because it is still a very effective strategy for reducing costs (even with the simplest option we are looking at ~35% cost reduction) without any kind of volatility associated.
  • Good, because it usually requires minimal changes to existing infrastructure - the only thing that needs to be done is changing existing on-demand instances to reserved instances.
  • Good, because it should not have any impact on the stability and resilience of the infrastructure (i.e. the API would behave exactly as it behaves with on-demand instances).
  • Bad, because cost reduction is not as attractive as with spot instances.

Comparative analysis between spot, reserved and on-demand

Below we have a simple analysis of the hourly costs for the different options considered in this document. All of them consider the pricing ($/h) for 1 m5a.xlarge EC2 instance. The assumed cost for spot instances is the current spot price at the time of writing.

  • On-demand cost: $ 0.172
  • 1-year reserved cost (no upfront payment): $ 0.108
    • (>> ~37% diff vs on-demand cost)
  • 3-year reserved cost (no upfront payment): $ 0.074
    • (>> ~57% diff vs on-demand cost)
  • Spot cost: $ 0.0756
    • (>> ~56% diff vs on-demand cost)

Reference links