CodePipeline / CodeBuild
CodePipeline is the AWS-native CI/CD service - integrates with CodeBuild, CodeDeploy, ECS, Lambda, S3. Good for AWS-heavy orgs.
AWS CodePipeline
EXAMPLE
# template.yaml - CodePipeline + CodeBuild via CFN
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
GitHubOwner: { Type: String }
GitHubRepo: { Type: String }
GitHubBranch: { Type: String, Default: main }
ConnectionArn: { Type: String, Description: CodeStar Connections ARN }
Resources:
ArtifactsBucket:
Type: AWS::S3::Bucket
BuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal: { Service: codebuild.amazonaws.com }
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
Build:
Type: AWS::CodeBuild::Project
Properties:
Name: myapp-build
ServiceRole: !GetAtt BuildRole.Arn
Source:
Type: CODEPIPELINE
BuildSpec: |
version: 0.2
phases:
install:
runtime-versions: { nodejs: 20 }
commands: [ 'npm ci' ]
build:
commands:
- npm run lint
- npm run test -- --coverage
- npm run build
artifacts:
files: [ 'dist/**/*', 'package.json', 'package-lock.json' ]
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:7.0
Type: LINUX_CONTAINER
Artifacts: { Type: CODEPIPELINE }
PipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal: { Service: codepipeline.amazonaws.com }
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess # tighten in prod
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt PipelineRole.Arn
ArtifactStore: { Type: S3, Location: !Ref ArtifactsBucket }
Stages:
- Name: Source
Actions:
- Name: GitHub
ActionTypeId:
{ Category: Source, Owner: AWS, Provider: CodeStarSourceConnection, Version: '1' }
Configuration:
ConnectionArn: !Ref ConnectionArn
FullRepositoryId: !Sub '${GitHubOwner}/${GitHubRepo}'
BranchName: !Ref GitHubBranch
OutputArtifacts: [ { Name: src } ]
- Name: Build
Actions:
- Name: Build
ActionTypeId: { Category: Build, Owner: AWS, Provider: CodeBuild, Version: '1' }
InputArtifacts: [ { Name: src } ]
OutputArtifacts: [ { Name: dist } ]
Configuration: { ProjectName: !Ref Build }
- Name: Deploy
Actions:
- Name: DeployToS3
ActionTypeId: { Category: Deploy, Owner: AWS, Provider: S3, Version: '1' }
InputArtifacts: [ { Name: dist } ]
Configuration:
BucketName: !Ref ArtifactsBucket
Extract: 'true'
# Triggers: any push to main on the configured GitHub repo
# Outputs to S3; swap Deploy stage for ECS, CloudFront invalidation, Lambda, etc.
Why it matters
CodePipeline shines when most of your build + deploy lives in AWS - tight IAM, native artefact handoff to ECS/Lambda/S3. For multi-cloud orgs, GitHub Actions is usually less friction. Either way, build artefacts once and deploy the same artefact to every environment.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
# Build + test + deploy pipelines — wired to CodeCommit / GitHub. # CodeBuild does the heavy lifting.Try it Yourself »
Discussion
Loading…