Use a blue/green deployment with the HalfAtATime configuration and the BeforeAllowTraffic hook to delete temporary files

Answer Correct answer: C — use a blue/green deployment with HalfAtATime traffic shifting 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?

  1. Use an Application Load Balancer and an in-place deployment. Associate the Auto Scaling group with the deployment group. Use the Automatically copy Auto Scaling group option, and use CodeDeployDefault.OneAtAtime as the deployment configuration. Instruct AWS CodeDeploy to terminate the original instances in the deployment group, and use the AllowTraffic hook within appspec.yml to delete the temporary files.
  2. Use an Application Load Balancer and a blue/green deployment. Associate the Auto Scaling group and Application Load Balancer target group with the deployment group. Use the Automatically copy Auto Scaling group option, create a custom deployment configuration with minimum healthy hosts defined as 50%, and assign the configuration to the deployment group. Instruct AWS CodeDeploy to terminate the original instances in the deployment group, and use the BeforeBlockTraffic hook within appspec.yml to delete the temporary files.
  3. Use an Application Load Balancer and a blue/green deployment. Associate the Auto Scaling group and the Application Load Balancer target group with the deployment group. Use the Automatically copy Auto Scaling group option, and use CodeDeployDefault.HalfAtAtime as the deployment configuration. Instruct AWS CodeDeploy to terminate the original instances in the deployment group, and use the BeforeAllowTraffic hook within appspec.yml to delete the temporary files. Correct Answer
  4. Use an Application Load Balancer and an in-place deployment. Associate the Auto Scaling group and Application Load Balancer target group with the deployment group. Use the Automatically copy Auto Scaling group option, and use CodeDeployDefault.AllatOnce as a deployment configuration. Instruct AWS CodeDeploy to terminate the original instances in the deployment group, and use the BlockTraffic hook within appspec.yml to delete the temporary files.

Community Votes

C
100%

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)

jamesf 👍 3 Selected: C
Option C is the best choice as it meets all the given requirements by utilizing a blue/green deployment strategy, correct traffic routing, proper temporary file cleanup timing, and automatic instance termination to manage costs. Option B is wrong due to: - Allows for custom deployment configuration, ensuring at least 50% of the instances must be healthy. However, "reroute to half" is somewhat ambiguous, as custom deployment with 50% only ensures half remain healthy but doesn't explicitly guarantee half reroute. - Uses BeforeBlockTraffic hook, which is not the correct timing for cleaning up temporary files because it should occur after instance provisioning but before allowing traffic.
tgv 👍 1
---> C
trungtd 👍 2 Selected: C
Automatically Copy Auto Scaling Group: This option allows launching a new fleet of instances for each deployment automatically. CodeDeployDefault.HalfAtAtime Deployment Configuration: This configuration meets the requirement of rerouting traffic to half of the new instances at a time. It ensures that the deployment succeeds if traffic is rerouted to at least half of the instances, otherwise, it fails.
6ef9a08 👍 3 Selected: C
B: blue/green deployment with CodeDeployDefault.HalfAtAtime

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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 →

← Back to DOP-C02 Study Guide