Q97 — AWS DOP-C02 Ch.1
Question 97 of 100 | ← Chapter 1
A company is using AWS CodePipeline to automate its release pipeline. AWS CodeDeploy is used in the pipeline with a blue/green deployment model to deploy applications to Amazon Elastic Container Service (Amazon ECS). The company wants to implement script-based tests on the green version of the application before traffic is shifted. These scripts must complete within five minutes or less. If errors are found during these tests, the application should automatically roll back.
- A. Add a stage in the CodePipeline between the source and deploy stages. Use AWS CodeBuild to create a runtime environment and build commands in the buildspec file to invoke the test scripts. If an error is detected, use the aws deploy stop-deployment command to stop the deployment.
- B. Add a stage in the CodePipeline between the source and deploy stages. Use this stage to invoke an AWS Lambda function that runs the test scripts. If an error is detected, use the aws deploy stop-deployment command to stop the deployment.
- C. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTestTraffic lifecycle event to invoke an AWS Lambda function to run the test scripts. If an error is detected, exit the Lambda function with an error status code to trigger rollback. ✓
- D. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTraffic lifecycle event to invoke the test scripts. If an error is detected, use the aws deploy stop-deployment CLI command to stop the deployment.
Correct Answer: C. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTestTraffic lifecycle event to invoke an AWS Lambda function to run the test scripts. If an error is detected, exit the Lambda function with an error status code to trigger rollback.
Explanation
AWS CodeDeploy's blue/green deployments use hooks defined in the AppSpec file to handle lifecycle events. Per AWS documentation, the AfterAllowTestTraffic event triggers before traffic is shifted to the green environment, enabling validation testing. Invoking a Lambda function at this stage to run tests—and returning an error exit code—causes CodeDeploy to automatically roll back the deployment. Option C correctly leverages this mechanism; other options either use incorrect lifecycle events or rely on external commands to stop deployment, which does not satisfy the requirement for automated rollback.