Soru

Zorluk: OrtaAWS CodeDeploy

A developer is configuring an in-place deployment to a fleet of Amazon EC2 instances registered with an Application Load Balancer using AWS CodeDeploy. The developer needs to run a local shell script named `verify_health.sh` to confirm that the application server is responding successfully on port 8080. This verification must execute after the application has started but before the instances are reregistered with the load balancer to receive production traffic. Which lifecycle hook in the `appspec.yml` file must the developer use to run this script?

  1. ValidateServiceCevap
  2. B
    BeforeAllowTraffic
  3. C
    ApplicationStart
  4. D
    AfterInstall

Cevap

ValidateService
The ValidateService lifecycle hook is the designated phase in EC2/On-Premises deployments to run verification scripts. It executes after the application has started (ApplicationStart) and before CodeDeploy reregisters the instances with the Application Load Balancer target group. A successful script exit code allows the deployment to proceed, while a non-zero exit code triggers an automatic rollback.

Adım Adım Çözüm

1
Identify the compute platform and deployment style.
Compute platform is Amazon EC2, and the deployment is an in-place update with a load balancer.
Different compute platforms (EC2 vs. ECS/Lambda) support different sets of AppSpec lifecycle hooks.
2
Determine which hooks support running user-defined scripts on EC2 instances.
Only specific hooks like BeforeInstall, AfterInstall, ApplicationStart, and ValidateService support script execution on EC2.
Load balancer hooks such as BeforeAllowTraffic are managed by CodeDeploy to update target group registration and cannot run user-defined scripts in the AppSpec file.
3
Order the lifecycle hooks to locate the correct phase after application startup but before traffic registration.
The ApplicationStart hook starts the service, followed by ValidateService to run health checks. Only after ValidateService passes does CodeDeploy proceed to BeforeAllowTraffic/AllowTraffic.
This guarantees that unhealthy instances are caught and the deployment is rolled back before they are exposed to production traffic.

Anahtar Kavram

AWS CodeDeploy AppSpec lifecycle hook execution order and capability differences between EC2/On-Premises and ECS/Lambda compute platforms.
Bu soruyu puanla