Sub topic 13
Observing health per Availability Zone
This chapter assumes you have read the earlier chapters on load balancing, Auto Scaling groups, and health checks. You should also know how to read CloudWatch metrics and use the AWS CLI.
A workload spread across three Availability Zones (AZs) can fail in just one of them. If your dashboards only show fleet-wide averages, a zonal failure is easy to miss. If one AZ out of three serves 100% errors, the fleet-wide error rate is about 33%. Latency averages and success-rate alarms tuned for whole-fleet problems may stay quiet. This chapter covers how to make the zone visible in your metrics, alarms, and runbooks.
Why fleet-wide metrics hide zonal failures
An average mixes healthy and unhealthy zones. Three situations show up in practice:
- Hard failure in one AZ. Instances or a dependency in that AZ stop responding. Health checks eject the targets, so users may see only a brief spike.
- Partial or gray failure. Instances pass the shallow health check, but requests are slow or fail intermittently. Nothing is ejected, and the zone keeps receiving traffic.
- Impairment outside your fleet. A zonal NAT gateway, a database primary, or a network path in one AZ degrades. Your instances look fine, but anything that depends on that component fails.
The technique that helps in all three is differential observability. You compare each AZ with its peers. A zone whose error rate is well above the others is the signal, even if the overall number looks acceptable.
Choose the zone identifier
The previous chapters covered the difference between AZ names and AZ IDs. For observability, the rule is to use the AZ ID (for example use1-az1) in anything you create yourself. The name us-east-1a can point to different physical zones in different accounts, so a runbook or cross-account dashboard that uses names can send people to the wrong zone. Some AWS-emitted metrics use the zone name, so keep a mapping table in your documentation. You can produce it with aws ec2 describe-availability-zones from the earlier chapter.
Metrics AWS already gives you per AZ
Elastic Load Balancing publishes several metrics with an AvailabilityZone dimension. These are the most useful ones to start with:
| Metric | What it tells you per AZ |
|---|---|
| `HealthyHostCount` and `UnHealthyHostCount` | How many targets in each zone pass or fail health checks. Use the `TargetGroup`, `LoadBalancer`, and `AvailabilityZone` dimensions. |
| `HTTPCode_Target_5XX_Count` | Errors returned by your targets in that zone. |
| `RequestCount` | How much traffic each zone receives, which you need to turn counts into rates. |
| `TargetResponseTime` | Latency seen from the load balancer, useful for catching gray failure. |
Not every metric supports every dimension combination. Check what exists in your account before building alarms:
aws cloudwatch list-metrics \
--namespace AWS/ApplicationELB \
--metric-name HTTPCode_Target_5XX_Count \
--query 'Metrics[].Dimensions[].[Name,Value]' \
--output tableOther sources add more per-zone information:
- Auto Scaling group metrics show the instance count in the group. They do not split by AZ, so compare
GroupInServiceInstanceswith what you expect from your zone layout. - NAT gateway metrics (
ErrorPortAllocation,PacketsDropCount,BytesOutToDestination) are per gateway. Each NAT gateway lives in one AZ, so a per-gateway alarm is also a per-AZ alarm. - AWS Health Dashboard events tell you when AWS is investigating a problem in an AZ. They are useful context, but they often arrive after your own metrics do. Don't wait for them.
Publish your own per-AZ metrics
Load balancer metrics show the front door. Your application knows more: whether the database call succeeded, how long the checkout took, whether the cache answered. To see these per zone, tag each metric with the AZ ID of the instance that produced it.
Each instance can read its own AZ ID from the instance metadata service (IMDS). This script uses IMDSv2 and publishes one data point:
#!/usr/bin/env bash
set -euo pipefail
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" \
-H "X-aws-ec2-metadata-token-ttl-seconds: 300")
AZ_ID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" \
http://169.254.169.254/latest/meta-data/placement/availability-zone-id)
aws cloudwatch put-metric-data \
--namespace Web/Checkout \
--metric-name CheckoutLatencyMs \
--dimensions AvailabilityZoneId="$AZ_ID" \
--value 120 \
--unit MillisecondsIn a real application you would use a client library or the CloudWatch agent, not a shell script. Whichever you use, set the AZ ID as a dimension once at startup and attach it to every metric and log line.
Keep the dimension set small. Every distinct combination of dimension values creates a separate custom metric, and each one is billed. AZ ID adds only two or three values, which is cheap. Adding instance ID as a dimension multiplies cost and does not help you spot a zonal problem.
Alarm on rates, not counts
A per-AZ count alarm misfires when traffic is uneven. After a failover one zone may carry twice the load, and its error count rises even if its error rate is unchanged. Use metric math to compute a rate and alarm on that.
This file defines a 5xx percentage for one AZ. Save it as metrics.json:
[
{
"Id": "errors",
"ReturnData": false,
"MetricStat": {
"Metric": {
"Namespace": "AWS/ApplicationELB",
"MetricName": "HTTPCode_Target_5XX_Count",
"Dimensions": [
{ "Name": "LoadBalancer", "Value": "app/web/50dc6c495c0c9188" },
{ "Name": "AvailabilityZone", "Value": "us-east-1a" }
]
},
"Period": 60,
"Stat": "Sum"
}
},
{
"Id": "requests",
"ReturnData": false,
"MetricStat": {
"Metric": {
"Namespace": "AWS/ApplicationELB",
"MetricName": "RequestCount",
"Dimensions": [
{ "Name": "LoadBalancer", "Value": "app/web/50dc6c495c0c9188" },
{ "Name": "AvailabilityZone", "Value": "us-east-1a" }
]
},
"Period": 60,
"Stat": "Sum"
}
},
{
"Id": "rate",
"Expression": "IF(requests > 0, 100 * errors / requests, 0)",
"Label": "5xx percent in us-east-1a",
"ReturnData": true
}
]Then create the alarm:
aws cloudwatch put-metric-alarm \
--alarm-name web-us-east-1a-5xx-rate \
--metrics file://metrics.json \
--comparison-operator GreaterThanThreshold \
--threshold 5 \
--evaluation-periods 3 \
--datapoints-to-alarm 3 \
--treat-missing-data notBreachingThree design choices in this alarm are worth understanding:
- The
IFguard. A zone with no requests would otherwise produce a division by zero and no data point. - Three of three datapoints. One bad minute is noise. Three in a row is worth acting on.
notBreachingfor missing data. If a zone legitimately has no traffic, you do not want a permanent alarm. Pair this with an alarm onHealthyHostCountso an empty zone is still caught.
Create one alarm per AZ, generated from a template so they stay identical.
Combine signals before you page or shift traffic
A single alarm can be wrong. A composite alarm joins several alarms with AND/OR logic. For example, you might page only when the 5xx rate alarm and the latency alarm for the same AZ are both in ALARM. You might also require that the other AZs are healthy. That last condition is the point of differential observability: if every zone is erroring, moving traffic between zones will not help, and the cause is probably a shared dependency or a bad deployment.
flowchart TDReplace nothing above; the actual diagram follows.
Once you have a trustworthy zonal signal, you can act on it. Amazon Application Recovery Controller (ARC) zonal shift moves traffic away from one AZ for supported load balancers. Zonal autoshift lets AWS do this for you when it detects an impairment. Both depend on the static stability work from the previous chapter. Shifting traffic is only safe if the remaining zones already hold enough capacity.
Test the signal from the user's side
Metrics from inside your load balancer miss problems that happen before requests reach it. CloudWatch Synthetics canaries send test requests on a schedule and record results. If you run one canary per zonal endpoint, you can see what a client sees. For a zone-specific check, point it at a zone-specific DNS name or a test target group so a failing zone cannot hide behind healthy ones.
Two further habits make this setup useful during an incident:
- Put zones side by side on one dashboard. Place each zone's error rate, latency, and healthy host count in identical widgets arranged in columns. Differences become visible at a glance.
- Log the AZ ID in every request log. CloudWatch Logs Insights can then group by AZ ID, so you can answer "is this only happening in one zone?" with a single query.
Exercise
Your three-AZ web tier shows a fleet-wide 5xx rate of 2%, which is below your 5% alarm threshold. Users in some regions report failures. What could explain this, and what change to your monitoring would expose it?
Show answer
One AZ could be failing heavily while the other two are healthy, so the average stays low. For example, 6% errors in one zone and 0% in two others averages 2%. Add per-AZ 5xx rate alarms based on the AvailabilityZone dimension and metric math (errors divided by requests, guarded against zero requests). Put the zones side by side on one dashboard and compare each zone with its peers.
Exercise
Why should a per-AZ alarm use an error rate instead of an error count, and why use AZ IDs instead of AZ names in your own custom metrics?
Show answer
After a failover or an uneven traffic split, a zone may receive much more traffic, so its error count rises even if the fraction of failing requests is unchanged. A rate stays comparable. AZ names such as us-east-1a can refer to different physical zones in different accounts, while an AZ ID such as use1-az1 identifies the same physical zone everywhere, so IDs keep dashboards and runbooks unambiguous.