Lifecycle Event Hooks in CodeDeploy

In biology, life cycle refers to the series of stages or events that occur during an organism’s lifetime. Lifecycle also applies when automating software deployment on AWS CodeDeploy. Lifecycle event hooks refer to the series of events that describes how a deployment is accomplished. It allows you to control or perform actions on different stages of your deployment.

In the traditional way, whenever you release a new feature for your application, you would have to manually disable the app and install the code. If the code resides in a repository like github, you’d have to manually download the code from github to your machine, make the necessary changes on your machine then restart the application. The lifecycle event hooks in CodeDeploy represent the manual steps taken during deployment. This way, the steps are automated so you can quickly release new features for your application and at the same time prevent downtime.

In this article, I will walk you through the different event hooks in CodeDeploy.

Event hooks are configured on a file called Application Specification file (AppSec). An AppSec file is nothing but a piece of a configuration file that can be written using YAML or JSON, which defines how an application is deployed. AppSec file is available for deploying on three platforms:

  1. Amazon ECS Compute Platform
  2. Amazon Lambda Compute Platform
  3. Amazon EC2/On-premises Compute Platform

Each of them has different hook events. For simplicity, we will be looking at deploying on an EC2 instance. You can find the information for the other two here:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-server

IT Certification Category (English)728x90

Here is an overview of the lifecycle event hooks on an EC2/On-premises platform:

Lifecycle Event Hooks in CodeDeploy1

Events:
Here’s a brief description of the lifecycle events so you can decide at which stage you are going to put custom actions as needed by your deployments.

  1. Start – This is the first event of the lifecycle event. The CodeDeploy Agent automatically executes this for you. This initiates the instance for deployment.
  2. ApplicationStop – it is the stage for running any scripts that will stop your old application. For example, if you have a new version of an e-commerce web application, let’s say v.1, this event will allow you to disable v.0 and prepare the instance to receive a new version, which in this case is v.1.
  3. DownloadBundle – During this event, the CodeDeploy Agent will pull the new version onto the instance.
  4. BeforeInstall – You can use this event to store the previous configuration of your old install that you want to keep, decrypt files, and create a backup of the current version.
  5. Install – During this event, the CodeDeploy Agent will copy the revision files to a file destination that you specify.
  6. AfterInstall – this event gives you the chance to change the configuration of your application before the application starts.
  7. ApplicationStart – As the name implies, you use this event to turn on your application which is now v.1 instead of v.0.
  8. ValidateService –  You can use this event to include any validation logic to determine that the deployment succeeded.
  9. End – This is the last event of the lifecycle event. This will notify the central service that the deployment to the instance was successful.

Things To Consider:

  • YAML is the only available format for configuring AppSec in EC2/On-premise.
  • You can either use YAML or JSON for configuring AppSec in ECS and Lambda.
  • You need to install the CodeDeploy Agent for configuring AppSec in EC2/On-premise.
  • For ECS and Lambda, you can directly use the online editor.
  • Referring to the diagram above, only the blue-colored events can be scripted. The rest are handled by the CodeDeploy Agent.

Sources:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-server
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-example.html
https://docs.aws.amazon.com/codedeploy/latest/userguide/application-specification-files.html#appspec-files-on-ecs-compute-platform
https://www.youtube.com/watch?v=A4NSyUbAEkw&t=2328s

BLACK FRIDAY Sale FINAL Week! Biggest Discounts on Practice Test + eBook Bundles

tutorials dojo black friday sale

NEW Course – AWS Certified Data Analytics Specialty Practice Exams

AWS Certified Data Analytics Sepcialty

Pass your AWS and Azure Certifications with the Tutorials Dojo Portal

Tutorials Dojo portal

Our Bestselling AWS Certified Solutions Architect Associate Practice Exams

AWS Certified Solutions Architect Associate Practice Exams

Enroll Now – Our AWS Practice Exams with 95% Passing Rate

AWS Practice Exams Tutorials Dojo

Enroll Now – Our Azure Certification Exam Reviewers

azure reviewers tutorials dojo

Tutorials Dojo Study Guide and Cheat Sheets eBooks

Tutorials Dojo Study Guide and Cheat Sheets-2

FREE Intro to Cloud Computing for Beginners

FREE AWS Practice Test Samplers

Browse Other Courses

Generic Category (English)300x250

Recent Posts