AWS Learning Journey

CodePipeline, CodeBuild, and CodeDeploy: CI/CD Without Leaving AWS

Buildspecs, build artifacts, deployment groups, ECS blue-green, Lambda traffic shifting, approval stages, and notifications — the AWS-native delivery toolchain, and when it beats GitHub Actions.

7 min read · 1373 words
AWSCI/CDDevOpsAWS CodePipelineContinuous Delivery
CodePipeline, CodeBuild, and CodeDeploy: CI/CD Without Leaving AWS cover image

AWS from Zero to Production — Phase 7, Part 3 of 5 · See the full series roadmap


Some teams can’t — or don’t want to — run deployments from outside AWS.

Maybe compliance requires that production deployments run inside the production account. Maybe builds need private network access to internal package registries. Maybe the organization already standardizes on AWS for everything, including audit trails.

For those teams, AWS has its own CI/CD toolchain:

This article explains each one, how they fit together, and how they compare with GitHub Actions.

What you’ll walk away with


AWS CodeBuild

CodeBuild is a fully managed build service. It runs your commands in a fresh container and bills by the minute.

The buildspec

A buildspec.yml in your repository defines the build:

version: 0.2

env:
  variables:
    REPO_NAME: orders

phases:
  install:
    runtime-versions:
      python: 3.12
    commands:
      - pip install -r requirements.txt -r requirements-dev.txt

  pre_build:
    commands:
      - pytest -q --junitxml=reports/junit.xml
      - ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
      - REGISTRY=$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
      - aws ecr get-login-password | docker login --username AWS --password-stdin $REGISTRY
      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c1-12)

  build:
    commands:
      - docker build -t $REGISTRY/$REPO_NAME:$IMAGE_TAG .

  post_build:
    commands:
      - docker push $REGISTRY/$REPO_NAME:$IMAGE_TAG
      - printf '[{"name":"orders","imageUri":"%s"}]' $REGISTRY/$REPO_NAME:$IMAGE_TAG > imagedefinitions.json

reports:
  unit-tests:
    files: [reports/junit.xml]
    file-format: JUNITXML

artifacts:
  files:
    - imagedefinitions.json

Docker builds need privileged mode enabled on the CodeBuild project.


AWS CodeDeploy

CodeDeploy automates deployments to:

Key concepts

Automatic rollback

A deployment group can roll back automatically when:

That second one is powerful: tie it to your error-rate alarm, and a bad release rolls itself back.


Lambda deployments with traffic shifting

For Lambda, CodeDeploy shifts traffic between two versions behind an alias:

Canary10Percent5Minutes:
  10% of traffic -> version 8, 90% -> version 7
  wait 5 minutes, watching alarms
  100% -> version 8

Linear10PercentEvery1Minute:
  +10% every minute until 100%

With AWS SAM, it’s just a few lines:

OrdersFunction:
  Type: AWS::Serverless::Function
  Properties:
    AutoPublishAlias: live
    DeploymentPreference:
      Type: Canary10Percent5Minutes
      Alarms:
        - !Ref OrdersErrorAlarm
      Hooks:
        PreTraffic: !Ref PreTrafficCheckFunction

Hooks run validation functions before and after traffic shifts. If a hook fails or the alarm fires, CodeDeploy shifts traffic back.


ECS blue-green deployments

You have two ways to do blue-green on ECS:

Built into ECS

ECS now supports native blue-green deployments — plus linear and canary — with lifecycle hooks and a bake time, without CodeDeploy. For new services, start here.

With CodeDeploy

The longer-established option. The ECS service uses the CODE_DEPLOY deployment controller:

An AppSpec for ECS:

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: orders
          ContainerPort: 8080
Hooks:
  - AfterAllowTestTraffic: "arn:aws:lambda:us-east-1:111122223333:function:orders-smoke-test"

AWS CodePipeline

CodePipeline connects everything into stages:

Source      GitHub (via CodeConnections) or Amazon ECR or S3
   |
Build       CodeBuild: test, build, push image
   |
Staging     Deploy to ECS (staging)
   |
Approval    Manual approval, with SNS notification
   |
Production  Deploy to ECS (production)

Pipeline type V2

Use the V2 pipeline type. It adds:

Connecting to GitHub

AWS CodeConnections (formerly CodeStar Connections) links CodePipeline to GitHub, GitLab, or Bitbucket through an installed app — again, no stored personal tokens.


Approval stages

A manual approval action pauses the pipeline until someone approves or rejects it:


Deployment notifications

Teams need to know when deployments start, succeed, or fail:

{
  "source": ["aws.codepipeline"],
  "detail-type": ["CodePipeline Pipeline Execution State Change"],
  "detail": { "state": ["FAILED"] }
}

AWS-native CI/CD vs. GitHub Actions

Choose AWS-native when

Choose GitHub Actions when

Or combine them

A common hybrid: GitHub Actions for CI — tests, scans, and building the image — and CodePipeline or CodeDeploy for the production deployment, triggered by a new image in ECR. Or GitHub Actions jobs running on CodeBuild-hosted runners inside your VPC.


Common mistakes


Key takeaways


Quick self-check

Test yourself before moving on:

  1. What file defines a CodeBuild build?
  2. How can a CodeDeploy deployment roll back automatically, even if it “succeeded”?
  3. What does Canary10Percent5Minutes do for a Lambda function?
  4. What does CodePipeline use to connect to GitHub without storing a token?

Answers

  1. buildspec.yml.
  2. By attaching CloudWatch alarms to the deployment group.
  3. Sends 10% of traffic to the new version for 5 minutes, then 100% if alarms stay healthy.
  4. AWS CodeConnections.

What’s next

In Part 4, we make the pipeline a security control: SAST, dependency scanning, container and IaC scanning, secret scanning, Amazon Inspector, SBOMs, artifact signing, and policy as code.

Does your team use AWS-native CI/CD, GitHub Actions, or both? Tell me why in the comments.


Share this article

LinkedIn post draft