AWS Certified Developer – Associate (DVA-C02)DeploymentMedium
A development team is deploying a new version of their Node.js web application to an Amazon EC2 instance using AWS CodeDeploy. They need to ensure that specific dependencies are installed and environment variables are set up before the application starts. Which CodeDeploy lifecycle event hook should they use for installing dependencies and configuring the environment?
- AApplicationStop
- BAfterInstall
- CInstall
- DBeforeInstall
Show answer & explanationAnswer & explanation
Correct answer: B. AfterInstall
The 'AfterInstall' hook is executed after the application revision files have been copied to the instance but before the application starts. This is the ideal stage to install dependencies, configure environment variables, and perform any other setup required before the application itself is launched.
Why the other options are wrong
- A. ApplicationStop is for gracefully stopping the currently running application, not for new installations.
- C. The 'Install' hook is primarily for installing the application's files, not typically for dependencies or environment configuration.
- D. BeforeInstall is executed before the new application revision files are downloaded and copied, which is too early for dependency installation.
CodeDeploy AfterInstall Hook
A CodeDeploy lifecycle event hook that executes after the new application revision has been copied to the instance, but before the application starts. It's used for post-installation setup.
- Runs after application files are copied.
- Ideal for installing dependencies and configuring environment variables.
- Precedes the 'ApplicationStart' hook.
Memory trick: AfterInstall: Files are there, now prep the stage for the show.