USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Building Pipelines with AWS CodePipeline and CodeBuild

Lesson 12/50 | Study Time: 35 Min

AWS provides two native services that work together to create a fully automated pipeline — CodePipeline orchestrates the flow, and CodeBuild does the actual building and testing. Together, they form the core of an AWS-native CI/CD setup.

The Two Services 

AWS CodePipeline

CodePipeline is the orchestrator. It defines the stages of your pipeline — source, build, test, deploy — and controls the flow of code through each stage. When something changes in your repository, CodePipeline detects it and kicks off the entire process automatically.

Think of CodePipeline as the manager that coordinates the workflow.

AWS CodeBuild

CodeBuild is the worker. It takes your source code, runs commands you define — install dependencies, run tests, compile code, create deployment packages — and reports the result back to CodePipeline.

Think of CodeBuild as the machine that actually does the building and testing.

How They Work Together


Every pipeline has at least two stages. Most have three or more.

The buildspec.yml File

CodeBuild is controlled by a file called buildspec.yml that lives in the root of your repository. This file tells CodeBuild exactly what commands to run and in what order.


yaml

version: 0.2

phases:

  install:

    runtime-versions:

      python: 3.11

    commands:

      - pip install -r requirements.txt


  pre_build:

    commands:

      - echo Running tests

      - pytest tests/


  build:

    commands:

      - echo Build started

      - zip -r app.zip . -x "*.git*"


  post_build:

    commands:

      - echo Build completed successfully


artifacts:

  files:

    - app.zip

```

### The Four Phases


| Phase | Purpose |

|---|---|

| **install** | Set up the environment — runtime versions, tools |

| **pre_build** | Run tests, linting, security scans before building |

| **build** | Compile code, create deployment package or Docker image |

| **post_build** | Notifications, cleanup, post-processing |


---

## 4. Setting Up a Pipeline — Step by Step


### Step 1 — Create a CodeBuild Project

```

AWS Console → CodeBuild → Create build project


Project name: my-app-build

Source: AWS CodeCommit → select your repository

Environment: Managed image → Amazon Linux → Standard runtime

Buildspec: Use buildspec.yml file in source code

Artifacts: Amazon S3 → select your artifact bucket

```

### Step 2 — Create the Pipeline in CodePipeline

```

AWS Console → CodePipeline → Create pipeline


Pipeline name: my-app-pipeline

Service role: Create new role (AWS manages permissions)


Source stage:

  Provider: AWS CodeCommit (or GitHub)

  Repository: your-repo

  Branch: main

  Detection: Amazon CloudWatch Events (triggers on every push)


Build stage:

  Provider: AWS CodeBuild

  Project: my-app-build


Deploy stage:

  Provider: Amazon S3 (for static apps) or AWS CodeDeploy (for servers)

  Bucket: your-deployment-bucket


Step 3 — Test the Pipeline

Push a change to your repository and watch the pipeline run automatically in the CodePipeline console. Each stage shows a progress indicator — green for success, red for failure.


IAM Permissions Required

CodePipeline and CodeBuild need IAM roles to interact with your AWS resources. AWS creates these automatically when you use the console, but it is important to know what they need:

Always scope these permissions to specific resources — not * — following least privilege.

Adding the Pipeline to Your Repository

For teams using GitHub, you can also define your pipeline as code. Store your buildspec.yml in your repository so it is version-controlled alongside your application code. This means:


1. Pipeline changes go through pull requests and code review.

2. You can roll back pipeline changes just like application changes.

3. Every developer can see exactly how the build works.

Drew Collins

Drew Collins

Product Designer
Profile

Class Sessions

1- What is DevOps? Principles, Culture, and Practices 2- The DevOps Lifecycle 3- Introduction to Cloud Computing 4- AWS Global Infrastructure 5- Core AWS Services Overview 6- Git Fundamentals 7- Branching Strategies 8- Pull Requests and Code Review Best Practices 9- Integrating Git with AWS CodeCommit and GitHub 10- Managing Secrets and Sensitive Files in Repositories 11- What is CI/CD? 12- Building Pipelines with AWS CodePipeline and CodeBuild 13- Automated Testing in CI 14- Deployment Strategies 15- Using GitHub Actions and Jenkins on AWS 16- Why Infrastructure as Code (IaC)? 17- AWS CloudFormation 18- Terraform on AWS 19- AWS Cloud Development Kit (CDK) 20- IaC Best Practices 21- Docker Fundamentals 22- Amazon ECR 23- Deploying Containers with Amazon ECS 24- Kubernetes Basics and Amazon EKS 25- Integrating Containers into CI/CD Pipelines 26- Serverless Computing Concepts and Use Cases 27- Building and Deploying AWS Lambda Functions 28- Event-Driven Automation with Amazon EventBridge 29- Orchestrating Workflows with AWS Step Functions 30- API Gateway Integration for Serverless APIs 31- Introduction to MLOps 32- Training and Deploying Models with Amazon SageMaker 33- Automating ML Pipelines with SageMaker Pipelines 34- Using Amazon CodeWhisperer and AI Tools for Code Automation 35- AI-Powered Testing, Anomaly Detection, and Incident Prediction 36- Observability Fundamentals 37- Amazon CloudWatch 38- Distributed Tracing with AWS X-Ray 39- Centralised Logging with Amazon OpenSearch Service 40- Setting Up Automated Alerts and Incident Response Workflows 41- Shift-Left Security 42- IAM Roles, Policies, and Least-Privilege Access 43- Static Code Analysis and Vulnerability Scanning in CI/CD 44- AWS Security Hub, GuardDuty, and Config for Compliance 45- Secrets Management with AWS Secrets Manager and Parameter Store 46- AWS Well-Architected Framework 47- Auto Scaling and Elastic Load Balancing for Resilience 48- Cost Monitoring with AWS Cost Explorer and Budgets 49- Disaster Recovery Strategies 50- Preparing Your Project for Production