Sub topic 7
Health checks for endpoints
This chapter assumes you can create a hosted zone and write records in it, and that you know what a TTL is. It covers how Route 53 health checks work, how to create one, and why a check does nothing until a record uses it.
What a health check does
A Route 53 health check is a monitor that tests an endpoint and reports it as healthy or unhealthy. The test comes from health checkers, which are servers spread across several AWS Regions. Each checker sends its own request at the interval you set. Route 53 treats the endpoint as healthy when more than 18 percent of the checkers report success.
Route 53 supports three kinds of health check:
| Kind | What it monitors | Typical use |
|---|---|---|
| Endpoint | A domain name or IP address, over HTTP, HTTPS or TCP | Web servers, load balancers |
| Calculated | The results of other health checks, combined with AND, OR or a minimum count | A service made of several parts |
| CloudWatch alarm | The state of a CloudWatch alarm | Endpoints in a private VPC that checkers cannot reach |
How a check connects to DNS
A health check does not change DNS by itself. It affects answers only when you attach it to a record through the record's HealthCheckId. Route 53 then leaves out the record when the check is unhealthy, and it answers with the remaining healthy records.
For an alias record, you can set EvaluateTargetHealth to true instead of creating a separate check. Route 53 then uses the health of the target resource, such as a load balancer.
Creating an endpoint health check
This command creates an HTTPS check that requests /health every 30 seconds:
aws route53 create-health-check \
--caller-reference "$(date +%s)" \
--health-check-config '{"Type":"HTTPS","FullyQualifiedDomainName":"www.example.com","Port":443,"ResourcePath":"/health","RequestInterval":30,"FailureThreshold":3}'The main settings are:
- Type is
HTTP,HTTPSorTCP. TheHTTP_STR_MATCHandHTTPS_STR_MATCHtypes also require a search string in the first 5,120 bytes of the response body. - RequestInterval is 30 seconds (standard) or 10 seconds (fast). The fast interval costs more.
- FailureThreshold is how many consecutive failed checks mark the endpoint unhealthy. It can be 1 to 10, and the default is 3.
- ResourcePath is the path requested for HTTP and HTTPS. A response with a 2xx or 3xx status counts as success.
With a 30-second interval and a threshold of 3, Route 53 needs roughly 90 seconds to notice a failure. A fast interval of 10 seconds with a threshold of 2 cuts that to about 20 seconds.
The command prints the new check's ID. Use it to read the current state:
aws route53 get-health-check-status \
--health-check-id HEALTH_CHECK_IDThe output lists the status each checker region reports, so you can see whether the failures come from everywhere or from one Region.
Common errors
- The check is never attached. A health check with no record using it changes nothing. Confirm that the record set has a
HealthCheckId. - Checkers are blocked. Firewalls and security groups must allow traffic from the Route 53 health checker IP ranges, which AWS publishes in
ip-ranges.json. Otherwise a healthy server is reported as unhealthy. - The endpoint is private. Health checkers sit on the public internet and cannot reach private IP addresses. Publish a CloudWatch metric from inside the VPC, alarm on it, and base the health check on that alarm.
- The endpoint is too slow. A TCP connection must succeed within 4 seconds. An HTTP response must start within 2 seconds of the connection. Slow startup under load shows up as failures.
- Failover seems slow. Even after the check turns unhealthy, resolvers keep serving the old answer until its TTL expires. Use a low TTL, such as 60 seconds, on records that need quick failover.
The next chapter attaches health checks to weighted, latency and failover records.
Exercise
You created an HTTPS health check with a 30-second interval and a failure threshold of 3. It reports unhealthy, but the server works from your laptop. Name two likely causes and one way to check each.
Show answer
First, the security group or firewall may block the Route 53 health checker IP ranges. Check the server's access logs for requests from those ranges, or compare the allowed ranges to the published ip-ranges.json. Second, the /health path may return a non-2xx/3xx status or respond too slowly to the checkers. Request that path with curl and check the status code and timing. The get-health-check-status output also shows each checker Region's result and reason.