r/aws • u/g0_g6t_1t • 16h ago
ci/cd What we learned running CI on one EC2 spot instance per job
TL;DR: one EC2 spot instance per GitHub Actions job. At the same 4 vCPUs as GitHub's 4-core runner (m8a's are full cores), build steps ran up to 2× faster and 7–12× cheaper, but every job waits ~40 s.
Build steps, cold medians, same run as GitHub (times on demand in us-east-1; costs on spot):
| Build | Time vs GitHub | Spot cost vs GitHub |
|---|---|---|
| Docker (grafana/k6) | 51 s vs 99 s, 1.9× | $0.0025 vs $0.024 |
| Go (cli/cli) | 34 s vs 73 s, 2.2× (8 jobs) | $0.0020 vs $0.024 |
| Python (pydantic) | 15 s vs 17 s, 1.1× (n.s.) | $0.0017 vs $0.012 |
Costs are spot plus gp3 from boot, at least 60 s billed. Spot got m8a.xlarge in 52 of 99 jobs and still built Docker 1.7× and Go 1.9× faster cold (1.4× and 1.2× warm).
When it doesn't pay: a t3.large control plane and a t3.small listener run all the time, about $86/month, so your Actions bill has to be well above that. Each job waits 34–46 s for its instance vs 4–5 s on GitHub.
What we learned:
- Spot m8a is often refused. Over three samples (17:00, 22:00 and 06:00 PST, three regions), m8a.xlarge spot launched in 44% of zones against m8i.xlarge's 81%; time of day didn't explain it. Don't let the SDK retry
InsufficientInstanceCapacity: failing fast took a spot launch from 40 s to 9.6 s. - m8a beat Graviton: at equal vCPUs on demand, 0.64–0.88× m8i's time; m8g was about as fast as m8i.
- gp3 throughput matters: at the free 125 MiB/s the image pull took 34 s vs 8 s at 500 MiB/s.
Why not CodeBuild-hosted runners or philips-labs' Terraform module (which can give a fresh VM per job in ephemeral mode)? We wanted one CLI for AWS, GCP and Azure.
We open sourced it as backmesh. https://github.com/backmesh/backmesh
What instance families have you found most reliable for spot CI?