0
0
AWScloud~5 mins

Health checks configuration in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Health checks help make sure your app or server is working well. They check if your service is alive and ready to handle requests. If a service is not healthy, AWS can stop sending traffic to it until it recovers.
When you want to automatically remove a broken server from your load balancer so users don't get errors.
When you run a website and want to make sure only healthy servers get user traffic.
When you deploy a new version of your app and want to check if it starts correctly before sending traffic.
When you want to monitor the health of your backend services in AWS Elastic Load Balancer.
When you want to reduce downtime by quickly detecting and replacing unhealthy instances.
Config File - health-check.json
health-check.json
{
  "HealthCheck": {
    "Target": "HTTP:80/health",
    "Interval": 30,
    "Timeout": 5,
    "UnhealthyThreshold": 2,
    "HealthyThreshold": 3
  }
}

This JSON configures a health check for an AWS Elastic Load Balancer.

  • Target: The protocol, port, and path to check (HTTP on port 80, path /health).
  • Interval: How often (in seconds) AWS checks the health.
  • Timeout: How long to wait for a response before marking it failed.
  • UnhealthyThreshold: Number of failed checks before marking instance unhealthy.
  • HealthyThreshold: Number of successful checks before marking instance healthy again.
Commands
This command applies the health check configuration to the load balancer named 'my-load-balancer'. It tells AWS how to check if instances are healthy.
Terminal
aws elb configure-health-check --load-balancer-name my-load-balancer --health-check file://health-check.json
Expected OutputExpected
{ "HealthCheck": { "Target": "HTTP:80/health", "Interval": 30, "Timeout": 5, "UnhealthyThreshold": 2, "HealthyThreshold": 3 } }
--load-balancer-name - Specifies the name of the load balancer to configure.
--health-check - Points to the JSON file with health check settings.
This command checks the current configuration of the load balancer to verify the health check settings were applied.
Terminal
aws elb describe-load-balancers --load-balancer-names my-load-balancer
Expected OutputExpected
{ "LoadBalancerDescriptions": [ { "LoadBalancerName": "my-load-balancer", "HealthCheck": { "Target": "HTTP:80/health", "Interval": 30, "Timeout": 5, "UnhealthyThreshold": 2, "HealthyThreshold": 3 } } ] }
--load-balancer-names - Specifies which load balancer to describe.
Key Concept

If you remember nothing else from this pattern, remember: health checks tell AWS when to send or stop sending traffic to your servers based on their real-time health.

Common Mistakes
Setting the health check path to a URL that does not return a simple success response.
The load balancer will mark instances unhealthy because it expects a quick, clear success response like HTTP 200.
Use a dedicated lightweight endpoint like /health that returns HTTP 200 when the app is healthy.
Setting the timeout longer than the interval between checks.
This causes overlapping checks and can confuse the health status results.
Set the timeout shorter than the interval, for example timeout 5 seconds and interval 30 seconds.
Not applying the health check configuration to the correct load balancer name.
The changes won't affect the intended load balancer, so unhealthy instances won't be detected properly.
Double-check the load balancer name matches exactly when running the configure-health-check command.
Summary
Create a JSON file defining the health check settings like target URL, interval, and thresholds.
Use the AWS CLI command to apply this health check configuration to your load balancer.
Verify the health check settings by describing the load balancer configuration.