Question 1
A financial services company is modernizing its application deployment strategy. They are using AWS CodePipeline and AWS CodeDeploy for blue/green deployments to an Amazon ECS cluster fronted by an Application Load Balancer (ALB). A critical requirement is to run a suite of integration tests against the new 'green' environment before any production traffic is shifted. These tests are invoked via an API call and can take up to 10 minutes to complete. If the tests fail, the deployment must be automatically rolled back without any traffic ever reaching the new version. Which configuration in the CodeDeploy AppSpec file will achieve this?
Answer and explanation
Correct answer: B
The AfterAllowTestTraffic hook is specifically designed for running tests in a blue/green deployment after the test listener is active but before production traffic is shifted. Triggering a Lambda function from this hook allows for external test suites to be run. If the Lambda function exits with an error (non-zero exit code), CodeDeploy will automatically initiate a rollback, preventing the faulty green environment from serving production traffic. BeforeInstall is too early in the lifecycle. AfterInstall happens before the task set is stable and ready for testing. BeforeAllowTraffic is for tasks just before the test listener traffic is allowed, which is also too early for end-to-end tests.