We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Target Groups

Now it's time to configure the load balancer to actually route traffic to our ECS tasks (instead of just returning its own fixed response). This is where Target Groups come in.

A target group tells the load balancer where to send traffic. It defines:

  • Protocol and port: What protocol (HTTP/HTTPS) and which port your tasks are listening on
  • Health checks: How the load balancer determines if a target is healthy
  • Target type: Whether targets are IP addresses (for Fargate) or instance IDs (for EC2)

For ECS with Fargate, we'll use the ip target type because each task gets its own IP address. The load balancer will route traffic directly to the task's IP address.

Health Checks

Target groups perform health checks to determine if targets are healthy and ready to receive traffic. The health check configuration includes:

  • Health check path: The endpoint to check (e.g., / or /health)
  • Health check interval: How often to check (e.g., every 30 seconds)
  • Health check timeout: How long to wait for a response (e.g., 5 seconds)
  • Healthy threshold: How many consecutive successful checks before marking as healthy (e.g., 2)
  • Unhealthy threshold: How many consecutive failed checks before marking as unhealthy (e.g., 2)

If a target fails its health checks, the load balancer stops sending traffic to it. Once it passes health checks again, traffic resumes automatically.

Health checks are crucial for reliability. If a container crashes or becomes unresponsive, the load balancer will detect it and stop routing traffic to it. This prevents users from hitting broken containers. Remember, ECS can run many backing containers!

Assignment

Create a target group named patientping-tg and update the load balancer listener to forward traffic to it instead of the static response.

The target group is now configured, but we don't have its targets configured yet. Don't worry, that's coming soon.

Run and submit the tests to verify your target group is configured correctly.