Use a blue/green deployment with the HalfAtATime configuration and the BeforeAllowTraffic hook to delete temporary files
A company is using AWS CodeDeploy to automate software deployment. The deployment must meet these requirements: • A number of instances must be available to serve traffic during the deployment. Traffic must be balanced across those instances, and the instances must automatically heal in the event of failure. • A new fleet of instances must be launched for deploying a new revision automatically, with no manual provisioning. • Traffic must be rerouted to the new environment to half of the new instances at a time. The deployment should succeed if traffic is rerouted to at least half of the instances: otherwise, it should fail. • Before routing traffic to the new fleet of instances, the temporary files generated during the deployment process must be deleted. • At the end of a successful deployment, the original instances in the deployment group must be deleted immediately to reduce costs. How can a DevOps engineer meet these requirements?
Community Votes
100% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The requirement to reroute traffic to half of the new instances at a time and to succeed if that half is healthy is precisely what the HalfAtATime deployment configuration does, and only blue/green supports the automatic replacement fleet and the distinct traffic-shift phase (C). The ordering requirement is what selects the hook: temporary files must be deleted before traffic reaches the new fleet, so BeforeAllowTraffic is correct, whereas BeforeBlockTraffic in option B runs at a different lifecycle point and the custom configuration with minimum healthy hosts applies to rolling deployments, not blue/green traffic shifting.
The requirements describe a blue/green deployment on an Application Load Balancer: a replacement fleet is launched automatically with no manual provisioning, traffic shifts to the new fleet half at a time, the deployment succeeds if that first half is healthy, temporary files must be deleted before traffic is routed, and the original instances must be terminated immediately on success. Blue/green with the automatically copy Auto Scaling group option satisfies the fleet requirement, CodeDeployDefault.HalfAtATime provides half-at-a-time traffic shifting with success determined by that first batch, the BeforeAllowTraffic hook deletes the temporary files before any traffic is routed, and terminating the original instances is configured on the deployment group.
Using the BeforeBlockTraffic hook to delete temporary files (B) — this hook fires around blocking traffic to the original instances rather than before traffic is allowed to the new environment, so it does not guarantee the files are gone before the new fleet receives traffic. Using an in-place deployment (A and D) — in-place updates instances in the deployment group in place and has no separate new fleet and traffic-shift phase, so the requirement for a newly launched fleet and half-at-a-time traffic shifting cannot be met. Using CodeDeployDefault.AllAtOnce (D) shifts all traffic at once, which contradicts the half-at-a-time requirement.
Community Discussion (4 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Each requirement maps to a specific part of the blue/green configuration. The replacement fleet must be launched automatically with no manual provisioning, which is what the Automatically copy Auto Scaling group option does when the deployment group is associated with an Auto Scaling group (C). Traffic must be rerouted to the new instances half at a time and the deployment must succeed if that first half is healthy, which is the behavior of the CodeDeployDefault.HalfAtATime deployment configuration: it shifts traffic to half the new fleet, and only if that succeeds does it continue to the remainder. The temporary files must be deleted before traffic is routed to the new fleet, which is exactly the BeforeAllowTraffic lifecycle event in appspec.yml, since it fires before the load balancer is allowed to send traffic to the replacement instances. Finally, instructing CodeDeploy to terminate the original instances immediately on success removes the cost of the old fleet. C is the correct answer.Why the Other Options Are Wrong
A uses an Application Load Balancer with an in-place deployment and the OneAtATime configuration. In-place deployments roll updates by replacing instances in the deployment group in place; there is no separately launched fleet and no traffic-shift phase, so the requirements for an automatically launched new fleet and for rerouting traffic to half of the new instances at a time cannot be satisfied. B uses blue/green correctly for the fleet, but deletes the temporary files with the BeforeBlockTraffic hook and uses a custom deployment configuration with minimum healthy hosts set to 50 percent. Minimum healthy hosts is a rolling-deployment concept, and BeforeBlockTraffic fires in the block-traffic phase rather than before traffic is allowed to the new environment, so the required ordering is not met. D uses an in-place deployment with the AllAtOnce configuration, which fails both the fleet requirement and the half-at-a-time traffic requirement. C is correct.Community Comment Notes
Community voted C unanimously. jamesf enumerated that C meets all the requirements through the blue/green strategy, the correct traffic routing configuration, the proper temporary-file cleanup timing, and automatic instance termination. trungtd identified that the Automatically copy Auto Scaling group option launches the new fleet automatically and that HalfAtATime provides the half-at-a-time shift. 6ef9a08 selected C but described the configuration as blue/green with HalfAtATime, consistent with the answer. No alternative received support.Official Reference
Related Analysis
Practice All DOP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full DOP-C02 Practice Test →