AWS Developer DVA-C02 · Deployment · hard
You are deploying an application to Amazon EC2 instances using AWS CodeDeploy (in-place deployment). Inside the root of your revision bundle sits the appspec.yml file defining lifecycle event hooks. In what exact chronological order does the CodeDeploy agent execute these four core lifecycle hooks during an EC2 deployment?
Published · Last updated · checked before publication — how we verify questions
Options
Answer: A. BeforeInstall -> AfterInstall -> ApplicationStart -> ValidateService
For an in-place EC2 or on-premises CodeDeploy deployment, the agent runs lifecycle events in a fixed order: ApplicationStop, DownloadBundle, BeforeInstall, Install, AfterInstall, ApplicationStart, ValidateService. The four hooks you can script in appspec.yml and that the question lists therefore run BeforeInstall, then AfterInstall, then ApplicationStart, then ValidateService. A helpful way to remember it is preparation, file copy, configuration, start, verify. BeforeInstall handles pre-install tasks such as backing up or decrypting files. Install is reserved for the agent, which copies the revision files to their destinations, and you cannot script it. AfterInstall is for configuration after the files are in place. ApplicationStart restarts or starts services, and ValidateService runs last to confirm the deployment worked. The most common trap is mixing up the hook names with the traffic-routing hooks used for load-balanced and Lambda or ECS deployments, or forgetting that the file copy sits between BeforeInstall and AfterInstall.
Why the other options are wrong
- B. ValidateService -> ApplicationStart -> BeforeInstall -> AfterInstall — This order reverses the sequence. ValidateService is the final hook and checks that the application is healthy after it has started, so it cannot run before ApplicationStart, BeforeInstall or AfterInstall.
- C. AfterInstall -> BeforeInstall -> ValidateService -> ApplicationStart — This places AfterInstall before BeforeInstall and ValidateService before ApplicationStart. BeforeInstall always runs before the Install event and AfterInstall, and ValidateService must follow ApplicationStart because it verifies a running application.
- D. BeforeAllowTraffic -> AfterAllowTraffic -> BeforeInstall -> ApplicationStart — BeforeAllowTraffic and AfterAllowTraffic are traffic-related hooks. They apply to load-balanced deployments and to Lambda and ECS deployments, and they run after the application is installed and started, never before BeforeInstall. The option also leaves out AfterInstall and ValidateService, so it does not describe the four core EC2 hooks.
More Deployment questions
- An AWS CloudFormation stack provisions an Amazon RDS production database and an Amazon S3 audit bucket. If a junior…
- A developer is writing a buildspec.yml file for AWS CodeBuild that compiles a Node.js TypeScript service, runs unit…
- A serverless team uses AWS SAM (template.yaml) and AWS CodeDeploy to deploy a new version of an AWS Lambda function…
- An application runs on AWS Elastic Beanstalk across a fleet of 6 EC2 instances behind an Application Load Balancer…
- In an AWS CloudFormation template, Stack A (NetworkStack) creates a production VPC and wants to export the VpcId so…
AWS and Amazon Web Services are trademarks of Amazon.com, Inc. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by Amazon Web Services.