CodeDeploy

  • To deploy the application automatically to EC2 instances or on-premises server
    • Note: They must be running CodeDeploy Agent
  • The AWS CodeDeploy Agent will continuously polling AWS CodeDeploy for work to do
    • They pull Application and appspec.yml from Github or S3
      • appspec.yml should be at the root of the project
        • files: Copy some extra files from S3 and Github to the filesystem
          • source: The source to copy from
          • destination: destination to paste to
        • hooks: set of instructions to do to deploy the new version. Can have timeouts. Follows the following order
          • ApplicationStop
          • DownloadBundle
          • BeforeInstall
          • Install
          • AfterInstall
          • Application Start
          • ValidateService (Important)
            • To make sure the service is working correctly
  • Agent then run the deployment instruction in appspec.yml
    • And then report success/failure status
      Pasted image 20221001154023.png

Primary components

  • Application

    • unique name for the application
  • Compute platform

    • EC2, on premises, Lambda, ECS
  • Deployment Configuration

    • Set of rules for success/failure. For example
      • EC2/On-premises: minimum of healthy instances
      • AWS Lambda / ECS: traffic is routed to the new instance
      • When Failure happens
        • EC2 instances will stay in failed
        • New deployments will first be deployed to failed instances
        • We can rollback, redeploy old deployment or enable automated rollback for failures
    • One At A time
      • Deploy 1 EC2 instance at a time. If one fails, then deployment stops
    • Custom
      • Can specify min healthy instances = 75%
    • All At Once
      • Quick but downtime, good for dev
    • Half At A time
      • We go 50% one by one
      • Pasted image 20221001155700.png
  • Deployment group

    • Group of EC2 instances (set of tagged EC2 instances)
    • ASG
    • Mix of ASG and Tags
    • Customisation in scripts with DEPLOYMENT_GROUP_NAME environment variables
  • Deployment type

    • In-place deployment
      • Supports by EC2, On-premises, ASG
      • For ASG, newly created EC2 instance will also get automatically deployed
      • For In-place deployment we have the above (all-at-one, half-at-one, one at a time)
    • Blue/Green Deployment
      • Supports by EC2, AWS Lambda and EC2
      • Use another ASG to deploy
      • If everything is healthy then v1 will be taken downPasted image 20221001160017.png
  • IAM instance profile

    • For EC2 to get permissions to access S3 and Github
  • Application Revision

    • Application code + appspect.yml
  • Service Role

    • IAM Role for CodeDeploy to perform operations on EC2 instance
  • Target Revision

    • Most recent revision that you want to deploy

Redeploy & Rollback

  • Can be rollback
  • We can disable rollbacks to not perform rollbacks as well
  • Note: If rollback happens, it will redeploy the last known good revision.
    • If we do an in-place upgrade, we need to re-deploy the original version. Only blue-green allow you to rollback.