Building CI/CD on AWS

(CodeCommit would make it all-AWS, but I used GitHub.)

Steps

I wanted GitHub code to be tested, built, and deployed to EC2. Commit your code to GitHub (I used master, but you can choose any branch). In CodePipeline, create a pipeline via the console. For the Source stage, connect GitHub via a webhook (simple through the UI).

For the Build stage I used CodeBuild, so I added a buildspec.yml to the repo root, e.g.:

version: 0.2
run-as: root
phases:
  build:
    commands:
      - # run tests/builds here
artifacts:
  files:
    - '**/*'

Create a build project, point its input artifact to the source output, and pick either an AWS-provided Docker image or your own (push custom images to ECR). Store build artifacts in S3.

For deployment I used CodeDeploy, so I added appspec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/src
hooks:
  BeforeInstall:
    - location: code_deploy/before_install.sh
      timeout: 300
      runas: root
  AfterInstall:
    - location: code_deploy/after_install.sh
      timeout: 300
      runas: root

This example extracts files to /var/src and lets you run scripts before/after install (e.g., adjust permissions). Create a deploy group and set the pipeline to use the artifact produced by CodeBuild.

Takeaways

Even without Jenkins or CircleCI you can build CI/CD purely on AWS. The benefits include consolidated cost management, tight service integration, and pay-as-you-go pricing for CodeBuild. At Japan IT Week I heard someone stress how crucial CI/CD automation is for fast development cycles—I completely agree.