AWS Series — Do you know how to get EC2 instance for less price?

Shilpa Thota
4 min readOct 5, 2024

--

Can we lower the price of a EC2 instance being charged? How can we do that? Will AWS give away that unused space?

Amazon EC2 Spot Instances

Amazon EC2 Spot Instances let you take advantage of unused EC2 capacity in the AWS Cloud. Spot Instances are available at up to a 90% discount compared to On-Demand prices.

Where would you use Spot Instances?

Stateless, fault-tolerant, or flexible applications. Applications such as big data, containerized workloads, CI/CD high-performance computing (HPC) and other test and development workloads.

What is the Process?

To use Spot Instances, you must first decide on your maximum Spot Price. the instance will be provisioned so long as the Spot Price is BELOW your maximum Spot Price.

For Example, if you choose $1 as maximum cost per hour. If the spot price is 50 cents per hour then it will provision your instance. If the spot price increases to $1.50 then it will either Terminate or Stop the instance based on what option you have chosen.

  • The hourly spot price varies depending on capacity and region.
  • If the spot price goes above your maximum, you have 2 minutes to choose whether to stop or terminate your instance.

We can also look at the Spot Price history and decide to choose the spot instance options.

Spot Instances are not useful for

  • Persistent workloads like database servers
  • Critical jobs which should be running and cannot be stopped
  • Databases cannot be provisioned on Spot instances as the data may be lost.

Terminating Spot Instances

This is the life cycle of spot instances. We create request with Max price, desired number of instances and the launch specifications i.e., AMI etc. The request type can be one-time or persistent. If the request type is persistent, we have to say when the request is valid from and when it’s valid to. With request type as one-time it is simple, we provision when the spot instance price goes down and meet our needs. It stops/terminates when it goes down. The spot request is completed.

If the Spot instance is selected as persistent, it looks if the request is open/active/disabled as opposed to failed/cancelled/closed. For Instance, if you get spot request that is open and persistent, you can’t just go in and terminate your instances because your spot request is going to look at the spot price and if spot price is still lower than the maximum price but there are no available instances. This will keep re provisioning those instances and gets struck in the loop.

To Terminate the spot instance first we go in and cancel the spot request and then Terminate the spot instance

What is Spot Fleets?

A Spot Fleet is a collection of Spot Instances and On-Demand Instances.

  • The Spot fleet attempts to launch the number of Spot instances and On-Demand instances to meet the target capacity you specified in the Spot Fleet request.
  • The request for Spot Instances is fulfilled if there is available capacity and the maximum price you specified in the request exceeds the current Spot price.
  • The Spot Fleet also attempts to maintain is target capacity fleet if your Spot Instances are interrupted.

Spot Fleets will try and match the target capacity with your price restraints

Launch Pools

  • We can set up different launch pools. Define the EC2 Instance type, Operating system and Availability Zone.
  • We can have multiple pools, and the fleet will choose the best way to implement depending on the strategy you define.
  • Spot Fleets will stop launching instances once you reach your price threshold or capacity desire.

Strategies to follow for Spot Fleets

  • Capacity Optimized — The Spot Instances comes from the pool with optimal capacity for the number of instances launching
  • Diversified — The Spot Instances are distributed across all pools
  • Lowest Price — The Spot Instances come from the pool with the lowest price. This is the default strategy
  • InstancePoolsToUseCount — The Spot Instances are distributed across the number of Spot Instance pools you specify. This parameter is valid only when used in combination with lowest Price.

Points to Remember for Spot Instances —

  • Spot Instances save up to 90% of the cost of On-Demand Instances
  • Useful for any type of computing where you don’t need persistent storage.
  • A Spot Fleet is a collection of Spot Instances and (Optionally) On — Demand Instances.

--

--

Shilpa Thota
Shilpa Thota

Written by Shilpa Thota

Full Stack Developer#TechEnthusiast#Manager#BigFan of Learning AI#

No responses yet