AWS CodePipeline Solution
The following graph shows the solution used for the project, which involves several stages and useful features. The AWS source capability enabled easy integration with a GitHub repository, and the fully automated solution triggers the pipeline on a code push to the branch. The CodeBuild service builds the images and performs initial testing of the application. Artifacts are published to AWS Elastic Container Repository (ECR), and the next step updates Lambda functions together with the static website hosted in an S3 bucket. CloudFront caches the S3 website in edge locations for faster delivery, and the following step uses the CodeBuild capability to force a cache update for CloudFront so customers can see the new version of the website immediately. The final stage consists of a Test action which runs in the development pipeline and allows us to test the entire application with the Cypress framework end-to-end.
Improving the speed of the build stage
The speed of the build is crucial for rapid integration. The Docker images built in the process consist of many layers, many of which do not change at all. The team utilised AWS capabilities to cache some of the layers to speed up the build process. The CodeBuild service is connected to ECR, where images are available from previous versions and use the layers that didn’t change. Although this solution didn’t impact the build process that much for this small application, it could significantly impact heavier images.
The biggest speed improvement to the pipeline came from running CodeBuild projects in parallel. When development started, there were few Lambdas, so building and deploying them sequentially was not an issue; however, as the project grew, so did the number of applications. We refactored the pipeline so that all applications were both built and then deployed concurrently, resulting in an exponential timesaving for developers and increased velocity for the team as a whole.
Infrastructure as Code
Our company promotes and utilises Infrastructure as Code (IaC) technology. Terraform is a cloud-agnostic tool that keeps infrastructure in order. The CodePipeline is specified in Terraform to help structure the different stages in place. Terraform also allows the modular creation of CodeBuild projects, which we implemented to easily add new applications to the CI pipeline. The architecture graph shows that CodeBuild “talks” to services such as ECR, S3, or CloudFront. All of them require IAM policies that allow for establishing that connection. Terraform serves as a remedy to prevent losing control over policies and roles in the project. They are specified directly in the repository in one place, allowing the connections without mixing with other IAM policies for other purposes in the account.
Low cost solution
AWS CodePipeline is a perfect solution for smaller and larger projects, with automation and integration benefits. The cost is reasonable, too: there are no upfront costs, and the first 30 days are always free. The pipeline won’t incur any costs if there are no code changes for over a month. CodeBuild is priced per minute, and it starts at only $0.0034 per minute for an ARM-based machine with 2 vCPU and 3 GB of memory.
AWS CodePipeline is an excellent tool for your CI/CD needs that seamlessly integrates with other AWS services and third-party providers. The pipeline can be adjusted to meet your application’s needs, regardless of its size. By using AWS CodePipeline, our team was able to implement a fully automated solution that accelerated the development process and enabled rapid iteration, ultimately allowing the client to deliver their solution to the project timeline