VG ALB
routing
Great question 👌 — let’s break this down step by step.
🔹 1. Condition vs Routing Rule
Condition → The “IF” part. What must match before ALB takes action. Example:
Host header =
example.comPath =
/api/*HTTP header contains
X-Env=prod
Routing Rule (Action) → The “THEN” part. What ALB should do if the condition matches. Example:
Forward traffic to Target Group A
Redirect to another URL
Return a fixed response
👉 Together: If condition is met → Apply routing rule (action).
🔹 2. Your Example: One domain (example.com), 3 services on same server
example.com), 3 services on same serverSuppose you have:
Service A → running on port 8081
Service B → running on port 8082
Service C → running on port 8083
All are on the same EC2 instance (same private IP).
You can configure 3 Target Groups, each pointing to the same instance but different port:
tg-service-a→ 10.0.1.5:8081tg-service-b→ 10.0.1.5:8082tg-service-c→ 10.0.1.5:8083
Then ALB Listener rules:
If Path =
/service-a/*→ forward totg-service-aIf Path =
/service-b/*→ forward totg-service-bIf Path =
/service-c/*→ forward totg-service-c
🔹 3. Example Rule Setup (in words)
Condition: Host header =
example.comAND Path =/service-a/*Action: Forward to Target Group A (port 8081)
Condition: Host header =
example.comAND Path =/service-b/*Action: Forward to Target Group B (port 8082)
Condition: Host header =
example.comAND Path =/service-c/*Action: Forward to Target Group C (port 8083)
🔹 4. Request Flow
User hits
https://example.com/service-a/ordersALB Listener checks Host =
example.com→ ✅ matchPath =
/service-a/*→ ✅ matchALB forwards to
tg-service-a→ instance:8081Service A responds → back through ALB → to user.
✅ So in short:
Conditions = "when should I trigger this rule?"
Routing Rules (Actions) = "what should I do when condition is met?"
⚡ Question for you: In your setup, do you want all 3 services under one domain with different paths (/service-a, /service-b, /service-c),
or under different subdomains (a.example.com, b.example.com, c.example.com)?
The ALB config changes slightly depending on this.
target type: instance - can send across mulitple port or instances
targte type: ip - farget/ecs - to multiple ip like ecs tasks ip
one load balancer - added in cname of cloudflare records and handling traffic
like when host header matches eg. apierpr02.officevg.com then route traffic to target
Last updated
