Q94 — AWS DOP-C02 Ch.3
Question 94 of 100 | ← Chapter 3
A company uses AWS CodePipeline to automate its release pipeline. AWS CodeDeploy is used in the pipeline with a blue/green deployment model to deploy the application to Amazon ECS. The company wants to run scripts to test the green version of the application before shifting traffic. These scripts must complete within five minutes or less. If errors are detected during this testing period, the company wants to roll back the deployment.
- A. Add a stage between the source and deploy stages in the CodePipeline pipeline. Use AWS CodeBuild to create an execution environment and define commands in the buildspec file to invoke test scripts. If errors are found, use the aws deploy stop-deployment command to halt deployment.
- B. Add a stage between the source and deploy stages in the CodePipeline pipeline. Use this stage to execute an AWS Lambda function that runs the test scripts. If errors are found, use the aws deploy stop-deployment command to halt deployment.
- C. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTestTraffic lifecycle event to invoke an AWS Lambda function that runs the test scripts. If errors are found, exit the Lambda function with an error to trigger automatic rollback. ✓
- D. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTraffic lifecycle event to invoke the test scripts. If errors are found, use the aws deploy stop-deployment CLI command to halt deployment.
Correct Answer: C. Add a hooks section to the CodeDeploy AppSpec file. Use the AfterAllowTestTraffic lifecycle event to invoke an AWS Lambda function that runs the test scripts. If errors are found, exit the Lambda function with an error to trigger automatic rollback.
Explanation
Option C is optimal. By adding a hook in the CodeDeploy AppSpec file and using the AfterAllowTestTraffic lifecycle event, testing occurs precisely before production traffic shifts. Invoking an AWS Lambda function enables flexible, serverless test execution. If the Lambda function fails (e.g., returns an error), CodeDeploy automatically triggers rollback—ensuring safety and reliability without custom CLI logic. Option D uses AfterAllowTraffic, which executes *after* full traffic shift, missing the pre-cutover validation window. Options A and B require external orchestration and manual rollback commands, increasing complexity and reducing reliability compared to native CodeDeploy rollback.