Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are the console steps to enable Auto Deploy and Monitoring for an existing AWS CodeDeploy deployment group (which your CodeBuild pipeline likely deploys to).
1. Enable Auto Deploy (Automatically deploy new revisions)
- Sign in to the AWS Management Console.
- In the top bar, choose the correct Region where your CodeDeploy resources exist.
-
Open CodeDeploy:
- Services → search for CodeDeploy → select it.
- In the left pane, choose Applications.
- Click the CodeDeploy application that your CodeBuild project/pipeline uses.
- Go to the Deployment groups tab.
- Click the Deployment group you want to fix.
- In the top-right, choose Edit.
-
Scroll to the Deployment settings / Triggers / Auto deploy section:
- Locate Auto deploy or Trigger deployments on new application revisions.
- Check/enable:
- Automatically deploy new revisions (or similar wording like “Trigger deployments when a new revision is pushed to the deployment group’s target repository/bucket”).
- If using:
- S3: select the bucket and prefix that contains your AppSpec and bundle.
- GitHub/CodeCommit: ensure the “Revision change” trigger is tied to the correct repository/branch.
-
(Recommended) In the same edit screen, enable Automatic rollback:
- Find Automatic rollback.
- Select:
- Rollback when a deployment fails.
- Optionally Rollback when alarm thresholds are met (we’ll set alarms next).
- At the bottom of the page, click Save changes.
2. Enable Monitoring with CloudWatch Alarms
You generally do this per deployment group by associating CloudWatch alarms that track instance/application health.2.1 Create or verify CloudWatch alarms
If you already have alarms that detect unhealthy deployments/instances, skip to 2.2.- Open CloudWatch:
- Services → CloudWatch.
- In the left pane, choose Alarms → All alarms → Create alarm.
- Click Select metric and choose a metric that reflects deployment health. Common patterns:
- EC2 / Application metrics like:
- CPU%, memory, or custom app health metric exposed to CloudWatch.
- Or a CodeDeploy metric (if using CodeDeploy metrics via CloudWatch):
- Example namespace:
AWS/CodeDeploy(depending on what you’ve configured) and metric for failed instances/deployments.
- Example namespace:
- EC2 / Application metrics like:
- Configure the alarm:
- Set the threshold so it goes to ALARM when your deployment is unhealthy (e.g., error count > 0, failed instances > 0).
- Configure actions (SNS topic, email, etc.) if desired.
- Click Next, give the alarm a Name and Description, and then click Create alarm.
2.2 Attach alarms and monitoring to the deployment group
- Go back to CodeDeploy → your Application → Deployment group (as in section 1).
- Click the Deployment group name, then choose Edit.
- Scroll to the Alarms / Monitoring / Deployment settings section:
- Find Alarms (or “Monitor deployments with CloudWatch alarms”).
- Check/enable Use CloudWatch alarms or similar.
- Click Add alarm and select the alarms you created in CloudWatch.
- Ensure Automatic rollback is set to:
- Rollback when alarm thresholds are met (in addition to “Rollback when deployment fails”, if desired).
- (Optional) In the same edit screen, ensure Log monitoring is enabled:
- If available, verify:
- The deployment group or underlying Auto Scaling group / instances use an IAM role that lets the CloudWatch Agent or CloudWatch Logs agent push logs.
- The logs are being sent to CloudWatch Logs (configured on the instances, not directly in CodeDeploy UI).
- If available, verify:
- At the bottom, click Save changes.
3. (If using CodeBuild/CodePipeline) Verify the integration
If CodeBuild is part of a pipeline that triggers CodeDeploy:- Open CodePipeline:
- Services → CodePipeline.
- Choose your pipeline and click Edit.
- Confirm:
- The Source stage outputs the artifact that CodeDeploy uses (e.g., AppSpec + bundle).
- The Deploy stage is a CodeDeploy action pointing to:
- The same Application name.
- The same Deployment group you just edited.
- Save the pipeline if any changes were made.
4. Validate
- Trigger a new build in CodeBuild or a new execution in CodePipeline.
- In CodeDeploy → Deployments, confirm:
- New deployments are automatically created when a new revision is produced.
- If you deliberately break a deployment (for testing), CloudWatch alarms move to ALARM, and CodeDeploy:
- Marks deployment as Failed.
- Performs Automatic rollback using the alarms (if configured).
Using CLI
Using CLI
In AWS, “Auto Deploy and Monitoring” for CodeDeploy is configured on the CodeDeploy deployment group, not on the CodeBuild project itself. You remediate this by updating the deployment group via AWS CLI to:
Use your own metric/dimensions/region as appropriate.
Key fields:
If you share your application and deployment group names (sanitized), I can give an exact command tailored to your setup.
- Enable CloudWatch alarms (monitoring)
- Enable automatic rollback (auto actions on failures/alarms)
1. Identify your CodeDeploy application and deployment group
You need:--application-name--deployment-group-name- List them if unsure:
2. (Optional) Create or identify CloudWatch alarms
If you don’t already have alarms, create them (example):3. Enable monitoring (CloudWatch alarms) and auto rollback
Runupdate-deployment-group to:- Turn on alarm monitoring
- Enable rollback on deployment failure and/or alarm
"enabled": trueunderalarm-configuration→ monitoring enabled."enabled": trueunderauto-rollback-configuration→ auto rollback enabled.events:DEPLOYMENT_FAILURE– rollback on deployment failureDEPLOYMENT_STOP_ON_ALARM– rollback when an alarm triggers.
4. (Optional) Ensure your CodeBuild → CodeDeploy pipeline uses this group
If you’re using CodePipeline:- Confirm the Deploy stage references
MyApplicationNameandMyDeploymentGroup. - No CLI change is needed in CodeBuild itself; the behavior is controlled entirely by the CodeDeploy deployment group you just updated.
If you share your application and deployment group names (sanitized), I can give an exact command tailored to your setup.
Using Python
Using Python
Below is how to remediate “CodeDeploy Auto Deploy and Monitoring should be enabled” using Python/boto3. This assumes you’re using AWS CodeDeploy as part of your pipeline (e.g., CodeBuild → CodeDeploy → target).There are two main things to enable:
This ensures that any deployments triggered from your CodeBuild pipeline use a CodeDeploy deployment group that has auto rollback and monitoring enabled, satisfying the “Auto Deploy and Monitoring should be enabled” requirement.
- Automatic rollback (auto deploy safety)
- Monitoring via CloudWatch alarms (so CodeDeploy can use alarms to stop/rollback bad deployments)
1. Prerequisites
- Python 3.x
-
boto3installed: -
AWS credentials configured (via AWS CLI profile, env vars, or instance profile):
-
You must know:
application_name(CodeDeploy Application)deployment_group_name(CodeDeploy Deployment Group)- The name(s) of CloudWatch alarms you want CodeDeploy to monitor.
2. Create / Identify CloudWatch Alarm(s)
If you don’t already have a CloudWatch alarm (e.g., on error rate, 5XX count, latency), create one via console or CloudFormation/Terraform.You only need the alarm name(s) in Python, e.g.:MyApp-High-5xxErrorsMyApp-High-Latency
3. Python script to enable Auto-Rollback and Monitoring
This script:- Retrieves existing deployment group config
- Updates it to:
- Turn on automatic rollback on
DEPLOYMENT_FAILURE(and optionally ALARM/CODE_DEPLOY_HEALTH) - Enable alarmConfiguration and attach your alarms
- Turn on automatic rollback on
4. Integrate with CodeBuild (optional)
In your CodeBuild project’s buildspec, you can:- Run tests
- If tests pass, call this script (once, or as part of environment setup)
- Then trigger CodeDeploy (e.g., via
aws deploy create-deployment)
buildspec.yml snippet:Using Terraform
Using Terraform
update-deployment-group CLI behavior and will overwrite any existing rollback/alarm configuration on this deployment group. No resource replacement is required; terraform plan should show in-place updates to auto_rollback_configuration and alarm_configuration for aws_codedeploy_deployment_group.CODEDEPLOY_DEPLOYMENT_GROUP.
