AWS CodePipeline (CI/CD Pipeline)

CICD Pipeline with CodeCommit CodeBuild and CodeDeploy

Build stage with AWS CodeBuild

In a CI/CD pipeline, the build stage compiles source code, runs tests, and packages artifacts. AWS CodeBuild is a fully managed build service that integrates seamlessly with AWS CodePipeline, scaling on demand and only charging you for build minutes used.

Preconfigured Build Environments

AWS CodeBuild offers a rich set of managed images out of-the-box:

RuntimeVersion Examples
JavaOpenJDK 8, Amazon Corretto 11
RubyMRI 2.7, 3.0
Go1.x
Node.js12.x, 14.x, 16.x
AndroidSDK 29–31
.NETCore 3.1, 5.0, 6.0
PHP7.4, 8.0
DockerDocker Engine 20.10

Note

You can also supply a custom Docker image stored in Amazon ECR or a public registry to match your exact build requirements.

The image lists various programming environments such as Java, Ruby, GoLang, Node.js, Android, Microsoft.NET, PHP, and Docker, under the heading "Preconfigured Environments."

CodeBuild Workflow

When you trigger a build, CodeBuild orchestrates the following steps:

  1. Provision a temporary compute container based on your project settings.
  2. Initialize the specified runtime environment.
  3. Download your source code from the configured repository.
  4. Execute lifecycle commands defined in buildspec.yml.
  5. Upload build artifacts to Amazon S3 or your chosen destination.
  6. Tear down the temporary container.

The image outlines the CodeBuild process in six steps: creating a temporary compute container, loading the runtime environment, downloading source code, executing project commands, uploading artifacts to S3, and removing the temporary container.

Here’s a sample buildspec.yml:

version: 0.2

phases:
  install:
    commands:
      - echo Installing dependencies...
      - npm install
  build:
    commands:
      - echo Running unit tests...
      - npm test
      - echo Building production bundle...
      - npm run build

artifacts:
  files:
    - 'build/**/*'
  discard-paths: yes
  base-directory: build

Warning

Avoid printing sensitive values (API keys, secrets) directly in build logs. Use AWS Secrets Manager or Parameter Store and inject them as environment variables.

Monitoring and Notifications

CodeBuild integrates natively with Amazon CloudWatch and SNS:

FeatureAWS ServicePurpose
Logs & MetricsAmazon CloudWatch LogsReal-time logs, custom metrics
Build Status AlertsAmazon SNSEmail, SMS, HTTP endpoint alerts
Event-Driven TriggersCloudWatch EventsAutomate downstream workflows

The image is a diagram showing AWS CodeBuild connected to AWS CloudWatch for monitoring and to Amazon Simple Notification Service (SNS) for notifications.

Automatic Scaling

AWS CodeBuild automatically adjusts the number of build containers to match your concurrent jobs. There’s no provisioning or server management—just pay for the time your builds run.

The image illustrates the concept of automatic scale-up and scale-down, showing multiple icons representing scaling processes with arrows indicating increase and decrease.

Summary

AWS CodeBuild provides a robust, scalable build service within your CI/CD pipeline. Key takeaways:

  • Fully managed continuous integration service
  • Preconfigured runtimes or custom Docker images
  • Deep integration: CodePipeline, CloudWatch, SNS, IAM, and more
  • Automatic scaling with pay-as-you-go pricing
  • Supports source from S3, CodeCommit, GitHub, Bitbucket, and others
  • Ideal for replacing or complementing self-hosted solutions like Jenkins
IntegrationAWS Service
Source ControlS3, CodeCommit, GitHub, Bitbucket
Build OrchestrationAWS CodePipeline, CodeBuild
Artifact StorageAmazon S3
Logging & MetricsAmazon CloudWatch Logs
Notifications & TriggersAmazon SNS, CloudWatch Events

The image is a summary slide about AWS CodeBuild, highlighting it as a building service, for continuous integration, and usable by itself.

A hands-on demonstration—setting up a CodeBuild project, configuring a buildspec, and running your first build—will reinforce these concepts.

Watch Video

Watch video content

Previous
Introduction to CodeBuild