CodeDeploy Automatic Rollback with CloudWatch Alarm: Health Check Failure
A company runs a critical application on Amazon EC2 instances behind an Application Load Balancer. The application is deployed using AWS CodeDeploy with an in-place deployment configuration. During a recent deployment, the deployment failed because the new application version caused a health check failure, and CodeDeploy did not automatically roll back. What should the engineer do to ensure automatic rollback on health check failure?
Quick Answer
The answer is to enable automatic rollback in the CodeDeploy deployment group and configure a CloudWatch alarm for the ALB health check. This works because CodeDeploy monitors the CloudWatch alarm state during a deployment; when the alarm enters ALARM—triggered by a health check failure—CodeDeploy automatically reverts the deployment to the last known good version. On the AWS Certified DevOps Engineer Professional DOP-C02 exam, this scenario tests your understanding of how CodeDeploy integrates with CloudWatch alarms to provide automated recovery, often appearing as a distractor where candidates mistakenly rely on manual rollback or deployment group settings alone. A common trap is forgetting that the alarm must be explicitly associated with the deployment group, not just created in CloudWatch. Remember the mnemonic: "Alarm + Auto-Rollback = Health Check Safety Net."
⚠ Common exam trap
Watch out — candidates often assume Auto Scaling group health checks or lifecycle hooks can handle deployment rollbacks, but they operate at the instance level and do not revert application code, whereas CodeDeploy's native automatic rollback with CloudWatch alarms is the correct, integrated solution.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Enable automatic rollback in the CodeDeploy deployment group and set up a CloudWatch alarm for the ALB health check
CodeDeploy can automatically roll back a deployment when a CloudWatch alarm, such as one monitoring ALB health check failures, enters the ALARM state. By enabling automatic rollback in the deployment group and associating the CloudWatch alarm, the deployment will revert to the previous version as soon as the health check fails, without manual intervention.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Set up an EC2 instance lifecycle hook to trigger a rollback script when the instance enters a pending state
Why it's wrong here
Lifecycle hooks are for custom actions during instance launch/termination, not for deployment rollback.
- ✗
Configure an Amazon SQS queue to monitor health checks and invoke a rollback Lambda function
Why it's wrong here
SQS is not integrated with CodeDeploy rollback; CodeDeploy has built-in rollback triggers.
- ✓
Enable automatic rollback in the CodeDeploy deployment group and set up a CloudWatch alarm for the ALB health check
Why this is correct
CodeDeploy can be configured to roll back when a CloudWatch alarm (e.g., based on health check metrics) is in ALARM state.
- ✗
Modify the Auto Scaling group to replace unhealthy instances automatically
Why it's wrong here
Auto Scaling replaces instances but does not roll back the deployment.
Go deeper
Related to this question
About these practice questions
This DOP-C02 question is part of Courseiva's 251-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on DOP-C02
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A DevOps engineer is designing a deployment pipeline for a microservices application on Amazon ECS. The team wants to use blue/green deployments with automatic rollback if CloudWatch alarms are triggered during the deployment. Which combination of services and configurations should the engineer use?
hard- ✓ A.Use AWS CodeDeploy with a blue/green deployment configuration on the ECS service, and configure automatic rollback when CloudWatch alarms are breached.
- B.Use AWS CloudFormation with a ChangeSet and a custom rollback Lambda function triggered by CloudWatch alarms.
- C.Use AWS CodeBuild to run a build that creates a new task definition, then update the ECS service manually, and use CloudWatch alarms to trigger a rollback via a Lambda function.
- D.Use Amazon ECS service auto scaling with step scaling policies based on CloudWatch alarms.
Why A: AWS CodeDeploy natively supports blue/green deployments on Amazon ECS services, and you can configure automatic rollback when CloudWatch alarms are triggered, meeting the team's requirements. Option B is incorrect because CloudFormation ChangeSets do not provide native blue/green deployment with automatic rollback based on alarms; custom Lambda functions add complexity. Option C is incorrect because CodeBuild is used for building artifacts, not deploying; manually updating the ECS service and using a Lambda for rollback is not a streamlined solution. Option D is incorrect because ECS service auto scaling handles scaling based on demand, not deployment strategies like blue/green.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.