We have a EC2 use case where we want to build our code on EC2, but these builds are infrequent.
Given that builds may take around 5-60 minutes and we build something 2-5 times a day, what is the best approach balancing cost and convienence?
Should we use a larger instance type with Spot Instances and EBS, and try to get staff to stop the instance when not needed? Should we be using T2 instead of T3, to make use of Launch credits?
Or should we have a smaller instance in Unlimited mode which we keep running to accure credits, to burn through when actully building?
Are there any other approaches that should be considered?
What CI/CD tool do you use? Jenkins? GitLab? Bamboo? GoCD? CodePipeline? Something else?
Most CI/CD tools have some way to spin up the build hosts only when needed, run the build, store the built artifacts (e.g. to S3) and stop the build host. All automatically as part of the CI/CD pipeline.
I would definitely consider Spot instances - ideally m5.something or c5.something. You can typically get these in spot very cheaply.
Don’t use T2/T3 - code building is a cpu intensive task, that’s not what T2/T3 is for.
Don’t rely on devs to manually start/stop the instances. They won’t.
If your build can be done in a container and if your CI/CD supports it try building in a Fargate container - no hosts to manage, faster to spin up and tear down and supports spot pricing as well.
And of course have a look at Amazon CodeBuild - managed service that is specifically designed for building packages from source code.
Plenty of options but depends on what your CI/CD tool can do.
Hope that helps :)