Amazon EC2 ELB alarm - which instance is unhealthy?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Amazon Elastic Load Balancer (ELB) is a vital component in distributing incoming application or network traffic across multiple targets, such as Amazon EC2 instances. Monitoring the health of these instances is crucial to maintain application availability and performance. ELB supports various alarm mechanisms to track and manage unhealthy instances effectively.
Understanding Amazon EC2 ELB Alarms
What are ELB Alarms?
ELB alarms are alerts configured within Amazon CloudWatch to notify the user when specific thresholds related to their ELB are breached. These metrics can include request count, latency, healthy/unhealthy host counts, etc. The focus here is on determining which EC2 instances under the ELB are unhealthy and how to set appropriate alarms to monitor this.
ELB Health Checks
Health checks are essential to determine the status of Amazon EC2 instances in relation to the load balancer. An instance is considered healthy if it can process requests, and unhealthy otherwise. Health checks can be configured using HTTP, HTTPS, TCP, or SSL, where the ELB periodically sends requests to the target instances.
Steps to Identify Unhealthy Instances
- Configure Health Checks: Ensure your ELB's health check is correctly set under "Health Check" in the ELB settings. Choose the appropriate protocol and define the path (e.g., `/health`) and response codes indicating a healthy instance.
- Setting Up CloudWatch Alarms: Use Amazon CloudWatch to create alarms based on ELB metrics to get notified whenever an instance becomes unhealthy.
- Metric: `UnHealthyHostCount`
- Threshold: Set a threshold (e.g., greater than 0) to trigger an alarm when any instance is marked as unhealthy.
Example of Setting Up an Alarm
- Navigate to the CloudWatch Console.
- Select 'Alarms' from the navigation pane.
- Click 'Create Alarm' and choose ELB as the metric source.
- Locate and select `UnHealthyHostCount` for the specific load balancer.
- Define Alarm Conditions:
- Choose a threshold, for example, when the `UnHealthyHostCount` is `GreaterThanThreshold` and set the threshold value to `0`.
- Set the data period (in minutes) to assess and a comparison operator such as `>` (greater than).
- Configure Actions:
- Specify actions when the alarm state is triggered, e.g., sending notifications via SNS (Simple Notification Service).
Technical Considerations
When implementing ELB alarms for unhealthy instances, consider the following:
- Duration and Interval: High interval periods may delay detection while shorter ones increase sensitivity but may also trigger false positives.
- Response Codes: Ensure the health check is configured to look for the correct HTTP response codes. For example, `200 OK` may indicate a healthy instance, whereas `404 Not Found` would not.
- Multi-Region Considerations: If your infrastructure is global, configure alarms on ELBs in each region for localized monitoring.
Enhanced Monitoring with CloudWatch
In addition to basic alarms, CloudWatch can be used for:
- Detailed Monitoring: Enabling detailed monitoring for EC2 instances can provide more granular data, useful for deep analysis and debugging.
- Custom Metrics: Implement custom CloudWatch metrics to track application-specific health indicators that may not be covered by standard ELB health checks.
Practical Troubleshooting Steps
When an alarm for unhealthy instances is triggered:
- Check ELB Logs: Use AWS CloudTrail logs to trace requests and identify anomalies.
- Review Instance Health: Access the EC2 Console to view health details and performance states.
- Analyze Network and Application Layers: Sometimes network misconfigurations or application bugs contribute to perceived unhealthiness.
- Adjust Health Check Parameters: If false alarms occur frequently, adjust parameters like threshold, path, and interval based on observed application behavior.
Key Points Summary
| Element | Description |
| EC2 ELB Health Check | Determines if instances are healthy or unhealthy based on response checks. |
| CloudWatch Metric | Monitors UnHealthyHostCount for alerting on instance health issues. |
| Threshold Setting | Configure alarms to trigger when the unhealthy count is greater than zero. |
| Actionable Steps | Set up SNS alerts, review CloudTrail logs, and adjust health check settings. |
| Regional Considerations | Implement monitoring and alarms across all deployed regions. |
By properly implementing and managing ELB alarms, AWS users can maintain a high level of application availability and structure a proactive approach to infrastructure awareness and troubleshooting.

