Save Money on CI/CD: Spot Instances for EC2
We realized savings of around 88% once we changed our CI/CD process from a dedicated instance to spot instances.
What are Spot Instances?
Spot instances are pretty much your regular EC2 instances with a big discount, the reason for that is that they rely on unused EC2 capacity on AWS. So prices are not fixed, they change — an auction for computing power.
When to use Spot Instances?
Non critical use cases. AWS puts it like this “You can use Spot Instances for various stateless, fault-tolerant, or flexible applications such as big data, containerized workloads, CI/CD, web servers, high-performance computing (HPC), and other test & development workloads.”
This is because prices and availability can change and AWS can reject a spot request if the bid is to low, or terminate an instance if the initial conditions change, so its gotta be something really fault-tolerant.
What did we do?
In our case, we wanted to take our CI/CD process to spot instances.

We needed a big instance because some of our pipelines workloads were massive and they could all be running at the same time. But those are processes that run every now and then, so we were actually wasting a lot of computing time and more importantly money!
We also use terraform a lot, and there happens to be a module for gitlab ci runners that uses spot instances

This is the cost of the new smaller runner. Its task is now just to spin up spot instances as required.
Spot instances have an hourly price. A month has around 730 hours. We are biding $0.035 per hour for t3.large instances that are big enough for individual workloads. So lets say we run pipelines that keep those kind of instances running half the month, so 365 hours at $0.035, we end up paying around $13 a month on top of the dedicated runner, giving a monthly total of around $23. Big Win!




