4.2.8 Health Checks and Readiness Probes

Application Health Checks and Readiness Probes

Per Service

ServiceHealth Check
ECSContainer HEALTHCHECK + ALB target group
EKSLiveness + Readiness probes
BeanstalkBasic (EC2) or Enhanced (app-level)
ALBHTTP health check on target path
LambdaCloudWatch error rate monitoring

ECS Container Health Check

HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
  CMD curl -f http://localhost:8080/health || exit 1

Elastic Load Balancing (ELB)

TypeUse CaseProtocol
ALB (Application)HTTP/HTTPS, path-based routingLayer 7
NLB (Network)TCP/UDP, ultra-low latencyLayer 4
CLB (Classic)LegacyLayer 4/7

ALB Features cho Developer

FeatureMô tả
Path-based routing/api/* → ECS, /static/* → S3
Host-based routingapi.example.com → Service A
Weighted target groupsCanary deployment (90/10 split)
Fixed responseReturn custom error pages
RedirectHTTP → HTTPS redirect
AuthenticationOIDC/Cognito integration
Sticky sessionsRoute same client to same target

Target Types

TargetService
InstanceEC2 instances
IPECS Fargate tasks, on-premises
LambdaLambda functions
ALBAnother ALB (chaining)

ALB Health Check Settings

SettingDefault
Path/
Interval30s
Timeout5s
Healthy threshold5
Unhealthy threshold2

Health Check Endpoint

def health_check(event, context):
    checks = {
        'database': check_db(),
        'cache': check_cache(),
        'external_api': check_api()
    }
    all_healthy = all(checks.values())
    return {
        'statusCode': 200 if all_healthy else 503,
        'body': json.dumps({'status': 'healthy' if all_healthy else 'unhealthy', 'checks': checks})
    }

Exam Tip: ECS = container HEALTHCHECK + ALB health check. Beanstalk Enhanced Health for app metrics. Health endpoint should check downstream dependencies.