0
0
AWScloud~5 mins

Health checks with Route 53 in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your website or app server might stop working. Health checks help automatically watch your servers and tell Route 53 if one is down. This way, Route 53 can send users to a working server instead of a broken one.
When you want to make sure users only reach servers that are working well.
When you have multiple servers and want to send traffic away from any that fail.
When you want to get alerts if your website or app stops responding.
When you want to automatically switch to a backup server if the main one is down.
When you want to improve your website’s reliability without manual checks.
Config File - health-check.json
health-check.json
{
  "CallerReference": "unique-string-20240601",
  "HealthCheckConfig": {
    "IPAddress": "192.0.2.44",
    "Port": 80,
    "Type": "HTTP",
    "ResourcePath": "/health",
    "RequestInterval": 30,
    "FailureThreshold": 3
  }
}

This JSON file defines a Route 53 health check configuration.

  • CallerReference: A unique string to identify this health check request.
  • IPAddress: The IP address of the server to check.
  • Port: The port number to connect to (80 for HTTP).
  • Type: The protocol used for the check (HTTP here).
  • ResourcePath: The path Route 53 requests to check server health.
  • RequestInterval: How often (in seconds) Route 53 checks the server.
  • FailureThreshold: How many failed checks before marking the server unhealthy.
Commands
This command creates a health check in Route 53 using the JSON configuration file. It tells AWS which server to check and how.
Terminal
aws route53 create-health-check --cli-input-json file://health-check.json
Expected OutputExpected
{ "HealthCheck": { "Id": "abcdef12-3456-7890-abcd-ef1234567890", "CallerReference": "unique-string-20240601", "HealthCheckConfig": { "IPAddress": "192.0.2.44", "Port": 80, "Type": "HTTP", "ResourcePath": "/health", "RequestInterval": 30, "FailureThreshold": 3 }, "HealthCheckVersion": 1, "HealthCheckStatus": "Healthy" } }
--cli-input-json - Specifies the JSON file with health check settings
This command retrieves details about the health check we just created to confirm it exists and see its status.
Terminal
aws route53 get-health-check --health-check-id abcdef12-3456-7890-abcd-ef1234567890
Expected OutputExpected
{ "HealthCheck": { "Id": "abcdef12-3456-7890-abcd-ef1234567890", "CallerReference": "unique-string-20240601", "HealthCheckConfig": { "IPAddress": "192.0.2.44", "Port": 80, "Type": "HTTP", "ResourcePath": "/health", "RequestInterval": 30, "FailureThreshold": 3 }, "HealthCheckVersion": 1, "HealthCheckStatus": "Healthy" } }
--health-check-id - Specifies the ID of the health check to get details for
This command lists all health checks in your AWS account so you can see all the checks you have set up.
Terminal
aws route53 list-health-checks
Expected OutputExpected
{ "HealthChecks": [ { "Id": "abcdef12-3456-7890-abcd-ef1234567890", "CallerReference": "unique-string-20240601", "HealthCheckConfig": { "IPAddress": "192.0.2.44", "Port": 80, "Type": "HTTP", "ResourcePath": "/health" } } ] }
Key Concept

If you remember nothing else from this pattern, remember: Route 53 health checks watch your servers and help send users only to servers that are working.

Common Mistakes
Using an incorrect IP address or domain in the health check configuration.
Route 53 will check the wrong server and mark your real server as unhealthy.
Double-check the IP address or domain you enter matches the server you want to monitor.
Setting the failure threshold too low, like 1.
Temporary network glitches can cause false alarms and mark a healthy server as down.
Use a failure threshold of at least 3 to avoid false positives.
Not specifying the correct resource path for HTTP checks.
Route 53 might get a 404 error and think the server is unhealthy.
Set the resource path to a simple URL that always returns a 200 OK status, like /health.
Summary
Create a health check JSON file to tell Route 53 which server and path to check.
Use the AWS CLI to create the health check with the JSON file.
Verify the health check exists and see its status with AWS CLI commands.
List all health checks to manage multiple servers.
Health checks help Route 53 send users only to healthy servers automatically.