4.2.8 Health Checks and Readiness Probes
Application Health Checks and Readiness Probes
Per Service
| Service | Health Check |
|---|
| ECS | Container HEALTHCHECK + ALB target group |
| EKS | Liveness + Readiness probes |
| Beanstalk | Basic (EC2) or Enhanced (app-level) |
| ALB | HTTP health check on target path |
| Lambda | CloudWatch 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)
| Type | Use Case | Protocol |
|---|
| ALB (Application) | HTTP/HTTPS, path-based routing | Layer 7 |
| NLB (Network) | TCP/UDP, ultra-low latency | Layer 4 |
| CLB (Classic) | Legacy | Layer 4/7 |
ALB Features cho Developer
| Feature | Mô tả |
|---|
| Path-based routing | /api/* → ECS, /static/* → S3 |
| Host-based routing | api.example.com → Service A |
| Weighted target groups | Canary deployment (90/10 split) |
| Fixed response | Return custom error pages |
| Redirect | HTTP → HTTPS redirect |
| Authentication | OIDC/Cognito integration |
| Sticky sessions | Route same client to same target |
Target Types
| Target | Service |
|---|
| Instance | EC2 instances |
| IP | ECS Fargate tasks, on-premises |
| Lambda | Lambda functions |
| ALB | Another ALB (chaining) |
ALB Health Check Settings
| Setting | Default |
|---|
| Path | / |
| Interval | 30s |
| Timeout | 5s |
| Healthy threshold | 5 |
| Unhealthy threshold | 2 |
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.