Mastering AWS Alerting and Automated Remediation
Alert notification and action capabilities (for example, CloudWatch alarms to Amazon SNS, Lambda, EC2 automatic recovery)
Read full articleMastering AWS Alerting and Automated Remediation
This study guide focuses on the critical DevOps capability of moving from reactive monitoring to proactive, automated response. We will explore how CloudWatch alarms, Amazon EventBridge, SNS, and Lambda work together to create a self-healing infrastructure.
Learning Objectives
After studying this material, you should be able to:
- Configure CloudWatch alarms with multiple actions (SNS, Lambda, EC2 recovery).
- Design event-driven architectures using Amazon EventBridge and S3 Event Notifications.
- Implement automated remediation for system failures and configuration drift.
- Distinguish between metric-based alerting (CloudWatch) and event-based alerting (EventBridge).
- Automate incident response for AWS Health events and CodeDeploy failures.
Key Terms & Glossary
- CloudWatch Alarm: A mechanism that watches a single metric over a specified time period and performs actions based on the value of the metric relative to a threshold.
- Amazon SNS (Simple Notification Service): A managed pub/sub service used to fan out notifications to endpoints like email, SMS, or Lambda.
- EventBridge (formerly CloudWatch Events): A serverless event bus that makes it easy to connect applications using data from your own applications, integrated SaaS applications, and AWS services.
- EC2 Automatic Recovery: A feature that automatically recovers an EC2 instance if it fails a system status check due to hardware issues.
- Metric Filter: A way to search and match terms or patterns in CloudWatch Logs and turn them into numerical metrics for alerting.
The "Big Idea"
In a professional DevOps environment, monitoring is only half the battle. The "Big Idea" here is Automated Operational Health. Instead of a human responder receiving a page at 3:00 AM to restart a service, the infrastructure identifies the failure (via CloudWatch or EventBridge) and triggers a targeted script (Lambda) or native AWS action (EC2 Recovery) to fix the state. This reduces Mean Time to Repair (MTTR) and ensures consistency across large-scale fleets.
Formula / Concept Box
CloudWatch Alarm Logic
An alarm's state is determined by three variables:
| Variable | Description |
|---|---|
| Threshold | The numerical value the metric is compared against (e.g., CPU > 80%). |
| Period | The length of time to evaluate the metric (e.g., 60 seconds). |
| Datapoints to Alarm | The number of data points within a set of evaluation periods that must be breaching (e.g., 3 out of 5). |
[!IMPORTANT] For High-Resolution Metrics, you can define periods as short as 1 second or 10 seconds, allowing for much faster reaction times than the standard 1-minute minimum.
Hierarchical Outline
- I. Metric-Based Alerting (CloudWatch Alarms)
- Standard Metrics: CPU, Disk, Network, Status Checks.
- Custom Metrics: Using the CloudWatch Agent to collect RAM usage or application-level logs.
- Alarm Actions:
- SNS: Pushing alerts to human operators or Slack.
- Auto Scaling: Triggering a change in the number of instances.
- EC2 Recovery: Moving an instance to a new host if the physical hardware fails.
- II. Event-Based Alerting (Amazon EventBridge)
- Pattern Matching: Triggering actions based on JSON event patterns (e.g., "Instance State is Terminated").
- AWS Health Integration: Responding to scheduled maintenance notifications.
- S3 Event Notifications: Triggering Lambda when a new log file is uploaded to an S3 bucket.
- III. Automated Remediation
- AWS Lambda: Running custom code to fix issues (e.g., rebooting a database).
- AWS Config Rules: Automatically reverting unauthorized security group changes.
- SSM Automation: Executing runbooks in response to CloudWatch Alarms.
Visual Anchors
CloudWatch Alerting Flow
EC2 Auto-Recovery vs. Reboot
Definition-Example Pairs
- Remediation: The act of fixing a resource that has drifted from its desired state.
- Example: An AWS Config rule detects a public S3 bucket and triggers a Lambda function to immediately set it to private.
- Fan-out: A design pattern where a single message is sent to multiple destinations simultaneously.
- Example: A CloudWatch Alarm triggers an SNS topic, which then sends an email to the team, a message to a Slack Webhook, and triggers a Lambda function to log the incident.
- Metric Stream: A continuous stream of CloudWatch metrics to a destination like Kinesis Data Firehose.
- Example: Sending all EC2 metrics to an S3 bucket for long-term historical analysis and compliance auditing.
Worked Examples
Scenario: Automating Slack Notifications for AWS Health Events
The Problem: AWS is performing maintenance on a host. We need to know about it in Slack immediately.
- Event Source: AWS Health sends a "Scheduled Maintenance" event to the default EventBridge bus.
- EventBridge Rule: Create a rule with an event pattern matching
source: aws.health. - Target: Select an AWS Lambda function as the target.
- Lambda Code (Python):
python
import urllib3 import json def lambda_handler(event, context): url = "https://hooks.slack.com/services/YOUR_WEBHOOK" msg = {"text": f"AWS Health Alert: {event['detail']['eventDescription'][0]['latestDescription']}"} http = urllib3.PoolManager() http.request('POST', url, body=json.dumps(msg), headers={'Content-Type': 'application/json'}) - Result: Whenever AWS schedules maintenance, the DevOps team gets a real-time Slack message.
Checkpoint Questions
- What is the primary difference between a System Status Check and an Instance Status Check in CloudWatch?
- Which service should you use if you want to trigger a response based on a specific API call (e.g.,
StopInstances) recorded in CloudTrail? - Can an EC2 Auto Recovery action preserve the same Instance ID and Private IP address?
- What happens to a CloudWatch Alarm if it doesn't receive data for the specified period?
▶Click to see answers
- System Status Checks monitor AWS infrastructure (hardware); Instance Status Checks monitor your software and network configuration.
- Amazon EventBridge (integrating with CloudTrail).
- Yes, Auto Recovery preserves Instance ID, Private IP, Elastic IP, and all metadata.
- It enters the
INSUFFICIENT_DATAstate (unless configured otherwise).
Muddy Points & Cross-Refs
- CloudWatch Alarms vs. EventBridge: Use Alarms for numerical thresholds (CPU > 90%). Use EventBridge for state changes (Instance STOPPED) or specific API events.
- Standard vs. High-Resolution Metrics: Standard is 1-minute; High-Res is up to 1-second. High-Res is more expensive but crucial for sensitive auto-scaling.
- Cross-Reference: See "AWS Systems Manager OpsCenter" for how to consolidate these alerts into a single management console.
Comparison Tables
Detection Methods: CloudWatch vs. EventBridge
| Feature | CloudWatch Alarms | Amazon EventBridge |
|---|---|---|
| Trigger Basis | Numerical Thresholds (Metrics) | JSON Patterns (Events) |
| Best For | Performance monitoring (CPU, Latency) | Operational changes (State, API calls) |
| Latency | 1 min (Standard) / 10s (High-Res) | Near real-time |
| Targets | SNS, EC2 Actions, Auto Scaling | Lambda, SQS, SNS, Kinesis, SSM |
| Cost | Per Alarm | Per Million Events |








