AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces deployable software packages. With CodeBuild, you don’t have to worry about provisioning, managing, or scaling your own build servers. Simply specify the source code location and choose your build settings, and CodeBuild will handle the execution of your build scripts.
CodeBuild operates on a pay-as-you-go pricing model, meaning there are no upfront costs or minimum fees. You are billed solely for the resources you utilize, and charges are based on the duration of your build execution.
There are three primary factors influencing build costs in CodeBuild:
- Build Duration
- Compute Types
- Additional Services
Understanding how to strike a balance between these factors is essential for cost optimization on AWS. This article will delve into each aspect.
Compute Types
CodeBuild offers three different compute instance types, each with varying amounts of memory and CPU. For instance, the Linux GPU Large compute type provides 255GB of memory and 32 vCPUs, enabling you to execute CI/CD workflows tailored for deep learning applications with AWS CodePipeline. Incremental changes in your code, data, and ML models can be accurately tested before being released through your pipeline.
The Linux 2XLarge instance type, boasting 145GB of memory and 72 vCPUs, is ideal for building large and complex applications requiring substantial memory and CPU resources. It can significantly reduce build times, accelerate delivery, and support multiple build environments.
While the GPU and 2XLarge compute types are powerful, they are also the priciest options per minute. For most tasks, the small, medium, or large instance types are more than sufficient. The pricing variability among these instance types can be illustrated using data from US East (Ohio).
Right Sizing Your Compute Types
Right sizing involves aligning instance types and sizes with your workload’s performance and capacity requirements while minimizing costs. It also means analyzing deployed instances to identify opportunities for downsizing or eliminating resources without sacrificing performance. Many organizations overlook right sizing when transitioning to the AWS Cloud. They often prioritize speed and performance over cost, leading to oversized instances and wasted resources.
CodeBuild automatically monitors build resource utilization and reports metrics through Amazon CloudWatch, including CPU, memory, and disk I/O. These metrics are accessible through the CodeBuild console, as shown in the example provided.
Exploring ARM/Graviton Options
When comparing the costs of arm1.small and general1.small over a ten-minute period, the arm-based compute type is 32% cheaper. However, the cost savings aren’t the only benefit; ARM processors are known for their energy efficiency and high performance. Compiling code on an ARM processor can lead to faster execution times and improved overall system performance.
The ideal workloads to migrate to ARM are those without architecture-specific dependencies, already running on Linux, and utilizing open-source components. For example, consider migrating AWS Lambda functions to Arm-based AWS Graviton2 processors. AWS Graviton processors are custom-built by Amazon to deliver optimal price performance for your cloud workloads. The AWS Graviton Fast Start program allows you to transition workloads to AWS Graviton in as little as four hours for applications like serverless, containerized, database, and caching.
Migrating Windows Workloads to Linux
By comparing the costs of a general1.medium Windows instance with a Linux compute type, we find that the Linux option is 43% less expensive over ten minutes. Transitioning to Linux can significantly lower the costs associated with building and testing code in CodeBuild, as well as reduce production running costs.
The complexity of re-platforming from Windows to Linux varies based on the application’s implementation. Identifying and targeting suitable workloads while balancing strategic importance and implementation effort is crucial. For instance, older .NET applications may need to be migrated to later versions of .NET before transitioning to Linux. AWS provides a Porting Assistant for .NET, which scans .NET Framework applications and generates a cross-platform compatibility assessment, expediting the porting process.
For further insights on this topic, you can explore another blog post here. Additionally, you can find more authoritative information at this link which discusses best practices in cloud optimization. For a community-driven perspective, check out this excellent resource on Reddit here that shares onboarding experiences.
Build Duration
The duration of each build significantly influences CodeBuild pricing, calculated from the time you submit your build until it is terminated, rounded up to the nearest minute. For example, if your build takes 35 seconds on an arm1.small Linux instance, you’ll be charged for the full minute, which is $0.0034. Similarly, a build taking 5 minutes and 20 seconds will incur a charge for 6 minutes.
When defining your CodeBuild project, you can specify phases such as install, pre-build, build, and post-build within a buildspec file. Each phase should only include necessary tasks; installing unneeded dependencies or executing irrelevant commands can inflate build times and costs. Additionally, packaging and uploading large files unnecessarily can have a similar impact.
Moreover, each build incurs additional time for queuing tasks, provisioning environments, downloading source code, and finalizing processes. For instance, it may take approximately 42 seconds in addition to the tasks outlined in the buildspec file, affecting the overall build duration.
Leave a Reply