š Hey there, tech explorer!
Iām Vikas Sankhla, Full Stack Developer and your friendly mentor from Web Codder.
Today, Iām going to explain Target Groups in AWS ā think of them like air traffic controllers, directing traffic to the right container at the right time! š«š¬
Letās learn how they work, how to use them with load balancers, and how to keep your apps smooth and fast! šØ
š§ What is a Target Group?
Imagine you run a food delivery app š. When someone orders food, you need to send that request to the right restaurant kitchen.
In AWS, the Target Group is like that kitchen list ā it tells the Load Balancer which backend services (containers or EC2 instances) should handle the request.
š¦ Basic Terms to Know
Term | Meaning |
---|---|
Load Balancer | Distributes traffic across servers š¦ |
Target Group | A list of places (targets) where traffic should go šÆ |
Target | A container, EC2, or Lambda that handles traffic š„ļø |
Health Check | A test to see if the target is alive ā |
Routing Rule | Tells AWS where traffic should go based on path, weight, etc. š§ |
š How Target Groups Work with Load Balancers
Letās make it super simple š”:
textCopyEditUser ā Load Balancer ā Target Group ā Healthy Container
ā”ļø When someone opens your app, the Load Balancer checks the Target Group.
ā”ļø The Target Group sends the traffic to a healthy ECS container.
ā”ļø If the container is sick (failing health checks), it gets skipped! š„ā
š§ Analogy: Bakery Example
- Load Balancer = The guy at the counter taking cake orders š
- Target Group = The list of bakers in the kitchen
- Target = Each baker (ECS container)
- Health Check = āHey baker, are you awake and ready?ā
- Routing = Decide which baker makes chocolate, which makes vanilla š
š ļø Step-by-Step: Configuring Target Groups in AWS
Letās set up a Target Group that routes traffic to ECS containers.
š£ Step 1: Create a Target Group
- Go to EC2 Dashboard in AWS Console.
- Click on Target Groups.
- Choose:
- Target Type = IP or ECS (based on setup)
- Protocol = HTTP or HTTPS
- Port = 80 (or your app port)
- VPC = Same VPC as your ECS service
š Give your Target Group a name like: myapp-target-group
𩺠Step 2: Set Up Health Checks
Health checks are super important.
They make sure only working containers get traffic! šŖ
Choose:
- Protocol: HTTP
- Path:
/health
(or whatever your app uses) - Healthy threshold: 3
- Unhealthy threshold: 2
- Interval: 30 seconds
šÆ This keeps traffic flowing to only healthy containers.
š Step 3: Attach Target Group to Load Balancer
- Go to your Application Load Balancer.
- Add a Listener on port 80 or 443.
- Add a Rule:
- Forward to ā
myapp-target-group
- Forward to ā
š„ Now traffic flows to your app like magic!
š§Ŗ Example: Routing with Target Groups
Letās say you have two versions of your app running:
Version | Target Group Name | Container Version |
---|---|---|
v1 | myapp-prod-v1-target | v1 |
v2 | myapp-prod-v2-target | v2 |
You can do:
šµ Path-Based Routing:
textCopyEdit/web ā myapp-prod-v1-target
/api ā myapp-prod-v2-target
So, different parts of your site go to different containers! š§
āļø Weighted Routing (for A/B Testing)
Want to try a new version of your app slowly?
You can split traffic:
- 80% of users ā v1
- 20% of users ā v2
AWS calls this weighted routing.
Itās great for blue/green deployments or A/B testing.
š Sample config (in rule editor):
jsonCopyEdit{
"forwardConfig": {
"targetGroups": [
{
"targetGroupArn": "arn:v1",
"weight": 80
},
{
"targetGroupArn": "arn:v2",
"weight": 20
}
]
}
}
š§¼ Best Practices for Target Groups
Best Practice ā | Why It Helps š§ |
---|---|
Always enable health checks | Keeps traffic going only to healthy containers |
Use path-based routing for microservices | Better organization |
Use weighted routing for updates | Smooth rollouts |
Monitor with CloudWatch | Catch issues early |
Use proper names like myapp-prod-api | Easy management |
š Infographic ā How Traffic Flows Through Target Groups


š§ In Short: Why Target Groups Matter
- They keep your app online, smooth, and smart.
- You can route traffic however you like: by path, by weight, or both.
- You can do safe rollouts, microservice routing, and traffic splitting like a pro š„.
š Bonus Tip: Use Multiple Target Groups!
Running multiple microservices?
Just create one Target Group per microservice and route each /service
path properly.
It makes scaling and debugging super easy! š
š Letās Stay Connected!
Did this article make Target Groups crystal clear?
Want more guides like this on ECS, Docker, and AWS?
šŗ Subscribe to my channel: Web Codder on YouTube
šø Follow me on Instagram: @web_codder_official
š¬ Chat with me on WhatsApp: webcodder.dev/whatsapp