CodeDeploy

Developer Associate

  • Automated deploy service which can deploy code into AWS infrastructure
  • Automatically scales with your infrastructure
  • Integrates with various CI/CD tools like Jenkins, GitHub, Atlassian, AWS CodePipelines, Ansible, Puppet and Chef
  • Supports two types of deployments
  • If deploying to EC2, you will use tags on instances for CodeDeploy to identify which instances to update
  • If deploying to EC2, you also need to install the CodeDeploy agent on your EC2 instance
    • The agent files are stored in S3 in the same region that your instance runs in.
  • AppSpec.yml defines everything about the deployment
    • version, os, source files and destination locations, and hooks to be run during the deployment in phases

In Place Deployments

  • The application is stopped on each instance and the latest revision is installed
  • The instance is out of service during this time and your capacity will be reduced
  • If the instances are behind a load balancer, you can configure the ELB to stop sending requests to instances being upgraded until they’re ready
  • This can only be used for EC2 or On-Prem systems
  • Drawback, if you need to roll back, the previous version of the app will need to be redeployed

Blue/Green Deployments

  • New instances are rprovisioned and the latest revision is installed on the new instance. Blue represents the active deployment, green is the new release
  • New instances are then registered with the ELB, and as soon as they’re ready they will start getting traffic.
  • Old instances are then terminated in favor of new instances
  • Advantages are that new instances can be created ahead of titme and the code is released to production simply by switching traffic to new servers
  • Switching back to the original environment is faster and more reliable as well because you just switch traffic back to the original servers as long as they’re not already terminated

Terminology (know for exam!!)

  • Deployment Group: A set of EC2 instances or Lambda functions to which a new revision of the software is to be deployed
  • Deployment: The process and components used to apply a new revision
  • Deployment Configuration: A set of deployment rules as well as success/failure conditions used during a deployment
  • AppSpec File: Defines the deployment actions you want AWS CodeDeploy to execute
  • Revision: Everything needed to deploy the new version.
  • Application: Unique identifier for the application you want to deploy.

AppSpec File

  • Used to define the parameters that will be used to deploy the CodeDeploy deployment
  • The AppSpec file MUST be placed in the root of the directory of your revision. If not, your deploy will fail (know this for exam!!)
  • For Lambda deployments, AppSpec can be written in YAML or JSON
    • version: for future use, only value is 0.0
    • resources: The name and properties of the Lambda function to deploy
    • hooks: Specifies Lambda functions to run at set points in the dpeoloyment cycle to validate things before or after the upgrade
      • BeforeAllowTraffic: used to specify the tasks or functions you want to run before traffic is routed to the newly deployed Lambda function
      • AfterAllowTraffic: used to specify the tasks or functions you want to run after the traffic has been routed to the newly deployed Lambda function
  • For EC2 or On Prem
    • version: for future use, only value is 0.0
    • os: Operating system you’re using, i.e. windows/linux
    • files: Location of any application files that need to be copied and where they should be copied to (source and destination folders). You can specify more than one set of souce/destination combinations
    • hooks: Lifecycle event hooks that allow you to specify scripts that need to be run at set points in the development cycle (try to know these for exam!!)
      • BeforeBlockTraffic: Run tasks on an instance before they are deregistered from a load balancer
      • BlockTraffic: Deregister instances from a load balancer
      • AfterBlockTraffic: Run tasks on an instance after they are deregistered from a load balancer
      • ApplicationStop: Gracefully stop the application in preparation for the new revision
      • DownloadBundle: The CodeDeploy agent copies the application revision files to a temporary location
      • BeforeInstall: Details of any pre-installation scripts (i.e. backup current version, decrypt files, etc.)
      • Install: The CodeDeploy agent copies the application revision files from their temporary location into their correct location
      • AfterInstall: Details of any post-installation scripts (i.e. configuration tasks, changing file permissions, etc.)
      • ApplicationStart: Restarts any services taht were stopped during ApplicationStop
      • ValidateService: Details of any tests to validate the service
      • BeforeAllowTraffic: Run tasks on instances before they are registered with a load balancer
      • AllowTraffic: Register instances with a load balancer
      • AfterAllowTraffic: Run tasks on instances after they are registered with a load balancer