AWS Certified Developer – Associate (DVA-C02)DeploymentHard

A developer is deploying an application to Amazon EC2 instances using AWS CodeDeploy. They need to execute a custom script on each instance immediately after the new application revision files have been copied to the instance, but before the application's dependencies are installed or the application starts. Which CodeDeploy lifecycle event hook should they use in their `appspec.yml` file?

  1. AAfterInstall
  2. BValidateService
  3. CBeforeInstall
  4. DApplicationStart
Show answer & explanation

Correct answer: C. BeforeInstall

The `BeforeInstall` lifecycle event hook in CodeDeploy runs after the application revision files are downloaded to the instance but before any installation or dependency resolution processes begin. This makes it the ideal place to execute a custom script that needs to run on the raw copied files before they are 'installed' or the application starts.

Why the other options are wrong

  • A. `AfterInstall` runs after the application and its dependencies are installed, which is too late for the specified requirement.
  • B. `ValidateService` runs after the application has started and is serving traffic, used for health checks, not for pre-installation scripts.
  • D. `ApplicationStart` runs after the application has been installed and started, which is also too late.

CodeDeploy BeforeInstall Hook

An AWS CodeDeploy lifecycle event hook that executes scripts after the application revision files are downloaded to an instance, but before any installation or dependency resolution begins, allowing for pre-installation setup tasks.

  • Runs after file copy.
  • Runs before installation/dependencies.
  • Useful for pre-setup tasks.

Memory trick: HOOK-ORDER: Hang On, On Every Kind Of Order, Really Do Everything Right.

More Deployment questions