Deploy Static Site to AWS on Commit

This is a quick cheat sheet for the steps involved to create a manual pipeline to deploy a static site with CDN and HTTPS to AWS automatically on commit, the simple solution nowadays is to use [Amazon’s Amplify] (https://aws.amazon.com/amplify/) but that wasn’t around back when I had to do this, but you might also need it if you have some non standard build requirements.

Buildspec

  • add buildspec.yaml to project

CodeCommit

  • create repository
  • add repo as remote to local git repo
  • push changes to remote repo

S3

  • create bucket
  • make public
  • enable static website hosting

CodeBuild

  • add build project
  • use ubuntu with base or whatever needed for project type e.g. Node
  • use latest runtime and image
  • use buildspec file
  • no artifacts
  • automaticaly create service role (use this to attach to policies later)

CodePipeline

  • add CodeCommit source stage
  • add CodeBuild build stage
  • skip deploy stage

Cloudfront

  • create web distribution
  • origin domain name is s3 bucket - do not use the one from dropdown should be in the format yourbucket.s3-website-ap-southeast-2.amazonaws.com
  • add alternate domain name
  • custom ssl import with ACM
  • Viewer Protocol Policy - redirect HTTP to HTTPS

ACM - AWS Certificate Manager

  • add full domain name
  • DNS validation
  • Create record in Route 53

IAM

  • Create Policy For S3 Write Acccess
  • Create Policy For Cloudfront
  • Add CodeBuild service role to policies

Route 53

  • A Record Alias pointing at Cloudfront distribution URL
comments powered by Disqus