liveBook · Manning

Health check

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A health check is an automated test that determines whether a website or backend target is able to receive traffic and provide an expected response.

A health check tests whether a website or backend is responding as expected. It can serve two different purposes: a load balancer uses checks to avoid sending requests to unhealthy targets, while an external website check can alert you when a site becomes unavailable. section 2.2.2 section 6.2

For an external website check, connect three AWS components:

  • A Lambda function sends an HTTP GET request and verifies that the response contains expected text. section 6.2
  • An EventBridge rule invokes the function every five minutes. section 6.2
  • A CloudWatch alarm watches failed checks and sends an email notification when the website is unavailable. section 6.2

To start in the AWS Management Console, create a Lambda function from the `lambda-canary` blueprint, give it a name, and select a new role with basic Lambda permissions. Create a scheduled rule with `rate(5 minutes)`. This approach runs the check periodically without keeping a virtual machine idle between checks; Lambda is billed by invocation. section 6.2.1 section 6.0

Checking a public website

A check can request `https://cloudonaut.io` and look for `cloudonaut` in the response. A response that lacks the expected text does not pass this check, even if the request reached the site. section 6.2

For an Application Load Balancer, configure health checks on its target group instead. The target group checks registered backends periodically, and the load balancer routes requests only to healthy targets. The example configuration checks `/index.html` over HTTP every 10 seconds, allows five seconds for a response, accepts HTTP codes 200–299, and sets healthy and unhealthy thresholds. section 2.2.2 section 14.1.1

Listing 14.2 Creating a load balancer and connecting it to an Auto Scaling group B
Listener:
  Type: 'AWS::ElasticLoadBalancingV2::Listener'
  Properties:
    DefaultActions:                          #1
    - TargetGroupArn: !Ref TargetGroup
      Type: forward
    LoadBalancerArn: !Ref LoadBalancer
    Port: 80                                 #2
    Protocol: HTTP
TargetGroup:
  Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
  Properties:
    HealthCheckIntervalSeconds: 10           #3
    HealthCheckPath: '/index.html'           #4
    HealthCheckProtocol: HTTP
    HealthCheckTimeoutSeconds: 5
    HealthyThresholdCount: 3
    UnhealthyThresholdCount: 2
    Matcher:
      HttpCode: '200-299'                    #5
    Port: 80                                 #6
    Protocol: HTTP
    VpcId: !Ref VPC

Use the target-group listing to locate the interval, path, protocol, timeout, thresholds, and accepted HTTP codes in a CloudFormation configuration. section 14.1.1

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Walks through console-based scheduling and gives concrete target-group settings, but does not detail health-check algorithms.
Examples
Uses a website GET request with expected text and a target-group check of `/index.html` accepting HTTP 200–299.
What it assumes
Introduces Lambda setup through the Management Console and a blueprint, using HTTP requests and responses as the check’s context.
What you can do after
Operate/configure it with a Lambda blueprint and scheduled rule, or with Application Load Balancer target-group settings.
How it connects
Connects health checks to AWS Lambda, EventBridge, CloudWatch alarms, Application Load Balancers, and target groups.

Also explained in

Compare how 9 books explain health check →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.