Target Group - VittorioDeMarzi/hero-beans GitHub Wiki
What Are Target Groups and Why Are They Created?
A Target Group is a logical grouping of "targets," such as EC2 instances, containers, or IP addresses, to which a load balancer (e.g., an Application Load Balancer) forwards traffic.
Think of a Target Group as a team of servers all performing the same job. They are created for two fundamental reasons:
-
Traffic Routing 🎯 The load balancer doesn't send traffic directly to individual instances, but to a Target Group. The rules you set on the load balancer's listener (e.g., "if traffic arrives on port 443 for the domain
mysite.com
...") determine which specific Target Group to send the request to. This allows you to manage multiple different applications or services (e.g., an API and a website) behind a single load balancer, each with its own group of servers. -
Health Checks ❤️🩹 The Target Group has the crucial task of constantly monitoring the health of the targets it contains. It performs checks at regular intervals (health checks) on the specified path (e.g.,
/actuator/health
). If an instance does not respond correctly, the Target Group marks it as "unhealthy," and the load balancer immediately stops sending traffic to it, redirecting it to the healthy instances. This mechanism is essential for ensuring the high availability and resilience of your application.
In summary, a Target Group defines WHERE the load balancer should send traffic and checks WHO is able to receive it reliably.
Guide: AWS Console → EC2 → Target Groups → Create target group
-
Target type: Instances.
- Choose this if your targets are EC2 instances.
-
Target group name:
- Use something clear and "greppable," for example:
tg-hero-beans-dev-8080
. - A good convention is
(tg- prefix, app, env, port)
. This way, you immediately know what it routes and where.
- Use something clear and "greppable," for example:
-
Protocol / Port: HTTP : 8080.
- The port on which your application (e.g., Spring Boot) is listening on the EC2 instances.
-
IP address type: IPv4.
- Your EC2 instances have private IPv4 addresses, and this is sufficient. Only choose IPv6 if you are already using an end-to-end IPv6 VPC. The ALB can still be "dualstack" at the listener level even if the Target Group remains on IPv4.
-
VPC: Select the VPC where the instances are located.
-
Protocol version: HTTP/1. ✅
- This is the perfect and safe choice for your Spring Boot app on
:8080
(classic REST). - Use HTTP/2 only if the backend specifically supports h2/h2c and you need an end-to-end HTTP/2 connection.
- Use gRPC only if your services communicate via gRPC.
- This is the perfect and safe choice for your Spring Boot app on
-
Health checks:
- Protocol: HTTP
- Path:
/actuator/health
(or any other endpoint your app uses to report its health status). - Success codes:
200
- The default settings for
Healthy threshold
,Timeout
, andInterval
(e.g., 5s/30s) are fine to start with.
-
Click on Create target group.
-
Once created, select the Target Group from the list, go to the Targets tab, and click Register targets.
- Select the EC2 instance(s) you want to add to the group.
- Click on Include as pending below.
- Verify and click on Register pending targets. The instances will begin the health check process and will become
healthy
if they respond correctly.