CodeDeploy fundamentals and appspec.yml

Automating Deployments on AWS

Dunieski Otano

Amazon Web Services Solutions Architect

What CodeDeploy does

flow

  • Releases code to EC2, Lambda, or ECS
  • Pulls the build artifact from S3, GitHub, or Bitbucket
  • Runs your deployment script through lifecycle events
  • Rolls back automatically if something fails
Automating Deployments on AWS

CodeDeploy core components

flow

  • Application: a name that groups deployments
  • Deployment group: which targets receive the release
  • Deployment configuration: how the rollout proceeds (instance batches or traffic shift)
  • Revision: the artifact bundle being deployed
Automating Deployments on AWS

Meet appspec.yml

appspec

  • YAML file at the root of the revision
  • version: 0.0 and os: linux required at the top
  • Tells CodeDeploy which files go where
  • Tells CodeDeploy what to run, and when
Automating Deployments on AWS

Lifecycle events on EC2

  • You write: ApplicationStop, BeforeInstall, AfterInstall
  • You write: ApplicationStart, ValidateService
  • System runs: DownloadBundle, Install
  • Each hook is a shell or PowerShell script on the instance

diagram

Automating Deployments on AWS

Lifecycle events on Lambda

  • Lambda has only two hooks: BeforeAllowTraffic, AfterAllowTraffic
  • Hooks are Lambda functions, not shell scripts
  • CodeDeploy shifts the alias to the new version
  • No instances to log into; no files to copy

comparison

Automating Deployments on AWS

A real appspec.yml for EC2

  • version: 0.0 and os: linux at the top
  • files: copy app.zip contents to /var/www/app
  • BeforeInstall, AfterInstall, ApplicationStart: lifecycle scripts
  • ValidateService: smoke-test confirms success

zip

Automating Deployments on AWS

Let's practice!

Automating Deployments on AWS

Preparing Video For Download...