0Pricing
AWS Solutions Architect · Lesson

Target Groups and Health Checks

Register EC2 instances, IP addresses, or Lambda functions as targets, and configure health check paths, thresholds, and intervals.

Target Groups and Health Checks is a free AWS Solutions Architect lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Are Target Groups?

A target group is a logical collection of targets that the load balancer routes requests to. Each target group has a target type, a protocol/port, and a health check configuration. The load balancer distributes requests to registered targets in the target group that pass health checks.

Target groups are associated with load balancer listeners through listener rules. One listener can route to multiple target groups based on request attributes. This is the core mechanism behind path-based and host-based routing in ALB.

# Create a target group for an ALB
aws elbv2 create-target-group \
  --name my-web-targets \
  --protocol HTTP \
  --port 80 \
  --vpc-id vpc-12345678 \
  --target-type instance \
  --health-check-path /health \
  --health-check-interval-seconds 30

Target Types: Instance, IP, Lambda

Target groups support three target types:

  • instance: routes to EC2 instances by instance ID; the load balancer sends traffic to the instance's primary network interface on the specified port
  • ip: routes to private IP addresses—useful for targets in containers (ECS/EKS), on-premises servers reachable via VPN/Direct Connect, or EC2 instances' secondary IPs
  • lambda: routes to a single Lambda function (ALB only); ALB converts the HTTP request to a JSON event and invokes the function synchronously

IP target type is required for ECS tasks with the awsvpc network mode (each task gets its own IP), for EKS pods, and for hybrid architectures with on-premises targets.

Registering Targets

You register targets with a target group manually (in the console or CLI) or automatically (via Auto Scaling Group attachment or ECS service configuration). Manually registered targets remain in the group until you explicitly deregister them.

For ASGs, you attach the ASG to a target group, and the ASG automatically registers newly launched instances and deregisters terminated ones. This tight integration with ASG is the standard pattern for elastic compute tiers—new instances come online and start receiving traffic as soon as they pass the health check.

# Register EC2 instances with a target group
aws elbv2 register-targets \
  --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-web-targets/abc123 \
  --targets Id=i-1234567890abcdef0 Id=i-0987654321fedcba0

# Register IP targets (for containers/ECS awsvpc)
aws elbv2 register-targets \
  --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-ip-targets/def456 \
  --targets Id=10.0.0.5,Port=8080 Id=10.0.0.6,Port=8080

Health Check Configuration

Each target group has an associated health check that the load balancer uses to determine if a target is healthy and eligible to receive traffic. The health check sends periodic requests to each target and evaluates the response:

  • Protocol: HTTP, HTTPS, or TCP (for NLB)
  • Path: the URL path to request (e.g., /health or /ping)
  • Port: the port to check (defaults to the target group port)
  • Healthy threshold: consecutive successes before marking healthy
  • Unhealthy threshold: consecutive failures before marking unhealthy
  • Interval: seconds between health checks (5–300)
  • Timeout: seconds to wait for a response

Health Check Success Codes

For HTTP/HTTPS health checks, you specify which HTTP response codes indicate a healthy target. The default is 200, but you can configure ranges like 200-299 or comma-separated values like 200,301,302.

Best practice: create a dedicated /health endpoint in your application that returns 200 only when all critical dependencies are available (database connectivity, cache, downstream service). Do not use the root URL (/) as the health check path if it performs expensive operations or requires authentication.

# Modify health check to accept 200-299
aws elbv2 modify-target-group \
  --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-web-targets/abc123 \
  --health-check-path /health \
  --matcher HttpCode=200-299 \
  --healthy-threshold-count 2 \
  --unhealthy-threshold-count 3 \
  --health-check-interval-seconds 15

Target States: Initial, Healthy, Unhealthy

A target progresses through these states after registration:

  • initial: ELB is performing the first health checks
  • healthy: passed the required consecutive health checks; receives traffic
  • unhealthy: failed the required consecutive health checks; removed from rotation
  • draining: deregistration is in progress; existing connections are allowed to complete but no new connections are sent
  • unused: registered in the group but no listener rule currently routes to this group

Monitor the UnHealthyHostCount and HealthyHostCount CloudWatch metrics to detect problems with your target fleet.

Deregistration Delay (Connection Draining)

Deregistration delay (formerly called connection draining) is the time ELB waits for existing connections to complete before finally deregistering a target. The default is 300 seconds (5 minutes). During this period, no new requests are sent to the deregistering target, but in-flight requests are allowed to finish.

For quick deployments and auto-scaling terminations, you may want to reduce this to 30–60 seconds if your application handles requests quickly. For long-running operations (file uploads, video processing), keep it long enough for those operations to complete without being interrupted.

# Reduce deregistration delay to 30 seconds
aws elbv2 modify-target-group-attributes \
  --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-web-targets/abc123 \
  --attributes Key=deregistration_delay.timeout_seconds,Value=30

Load Balancing Algorithms

Target groups support different load balancing algorithms:

  • Round robin (ALB default): requests distributed evenly in rotation—best when all targets are equivalent
  • Least outstanding requests (ALB): sends each new request to the target with the fewest in-flight requests—better for variable-length workloads where some requests take longer than others
  • Flow hash (NLB): distributes based on protocol, source/destination IP, source/destination port, and TCP sequence number—ensures all packets in a TCP/UDP flow go to the same target

For session-based applications where all requests from a user must reach the same target, enable sticky sessions instead of relying on round-robin distribution.

Multiple Target Groups and Weighted Routing

A single ALB listener rule can distribute traffic across multiple target groups with weighted target groups. For example, route 90% of traffic to a stable target group and 10% to a canary target group for blue-green deployments—without using Route 53 weighted routing.

Weighted target groups are configured at the listener rule level. The weights are relative: 90/10 sends 90% to the first group and 10% to the second. This is different from weighted routing across multiple ALBs; here it is within a single ALB listener rule.

Target Groups and ECS Integration

When deploying ECS services behind an ALB, each ECS task gets registered with the ALB target group using the ip target type (for awsvpc network mode). The ECS service manages registration and deregistration automatically: new tasks are registered after passing health checks, and stopping tasks trigger deregistration delay before termination.

Each ECS service can register with a specific port override, allowing multiple ECS services to share a single ALB via different listener rules (path-based or host-based) with different target groups—a common microservices pattern.

NLB Health Checks

NLB health check behaviour differs from ALB:

  • NLB supports TCP, HTTP, and HTTPS health check protocols regardless of the listener protocol
  • NLB health checks are sent from the NLB's IP addresses in each AZ—ensure security groups allow traffic from the NLB's subnet IPs or use the security group of the NLB itself
  • For TCP health checks, NLB considers a target healthy if it accepts a TCP connection on the specified port
  • NLB targets that fail health checks are removed per AZ—if an AZ's targets are all unhealthy, NLB may cross-zone load balance to healthy targets in other AZs (if cross-zone LB is enabled)

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: target groups contain healthy registered targets of type instance, IP, or Lambda, health checks periodically probe targets to remove unhealthy ones from rotation, and deregistration delay ensures graceful draining of in-flight requests before target removal. Next up we explore listener rules and path-based routing on the ALB.

Frequently asked questions

Is the “Target Groups and Health Checks” lesson free?

Yes — the full text of “Target Groups and Health Checks” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “Target Groups and Health Checks”?

Register EC2 instances, IP addresses, or Lambda functions as targets, and configure health check paths, thresholds, and intervals. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Target Groups and Health Checks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. ALB vs NLB vs GLB: When to Use Which
  2. Target Groups and Health Checks
  3. Listener Rules and Path-Based Routing
  4. SSL Termination and Sticky Sessions
← Back to AWS Solutions Architect