Q26 — AWS DOP-C02 Ch.2
Question 26 of 100 | ← Chapter 2
A company developed an AWS Lambda function to process orders received via an API. The company uses AWS CodeDeploy to deploy the Lambda function as the final stage of its CI/CD pipeline. A DevOps engineer notices intermittent failures in the order API within seconds after deployment. After investigation, the DevOps engineer determines the failures occur because database schema changes have not yet propagated fully before the Lambda function is invoked.
- A. Add a BeforeAllowTraffic hook to the AppSpec file that tests and waits for any required database changes before traffic is routed to the new version of the Lambda function. ✓
- B. Add an AfterAllowTraffic hook to the AppSpec file that forces traffic to wait for pending database changes before allowing the new version of the Lambda function to respond.
- C. Add a BeforeInstall hook to the AppSpec file that tests and waits for any required database changes before deploying the new version of the Lambda function.
- D. Add a ValidateService hook to the AppSpec file that inspects incoming traffic and rejects payloads when dependent services (e.g., database) are not ready.
Correct Answer: A. Add a BeforeAllowTraffic hook to the AppSpec file that tests and waits for any required database changes before traffic is routed to the new version of the Lambda function.
Explanation
AWS CodeDeploy uses the AppSpec file to define lifecycle hooks for Lambda deployments. According to AWS documentation, the `BeforeAllowTraffic` hook executes just before traffic is shifted to the new Lambda version, making it ideal for verifying prerequisites like database readiness. Since the failure stems from incomplete database propagation, waiting at this stage ensures stability before traffic flows. Options B (`AfterAllowTraffic`) runs after traffic has already started, too late to prevent errors. Option C (`BeforeInstall`) runs before code deployment—not after—and cannot verify runtime dependencies. Option D (`ValidateService`) is not a standard CodeDeploy lifecycle event for Lambda. AWS CodeDeploy documentation explicitly defines `BeforeAllowTraffic` as the final pre-traffic verification checkpoint.