VG ALB

chevron-rightresources maphashtag

chevron-rightroutinghashtag

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.com

    • Path = /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

Suppose 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:8081

  • tg-service-b → 10.0.1.5:8082

  • tg-service-c → 10.0.1.5:8083

Then ALB Listener rules:

  • If Path = /service-a/* → forward to tg-service-a

  • If Path = /service-b/* → forward to tg-service-b

  • If Path = /service-c/* → forward to tg-service-c


🔹 3. Example Rule Setup (in words)

  • Condition: Host header = example.com AND Path = /service-a/*

    • Action: Forward to Target Group A (port 8081)

  • Condition: Host header = example.com AND Path = /service-b/*

    • Action: Forward to Target Group B (port 8082)

  • Condition: Host header = example.com AND Path = /service-c/*

    • Action: Forward to Target Group C (port 8083)


🔹 4. Request Flow

  1. User hits https://example.com/service-a/orders

  2. ALB Listener checks Host = example.com → ✅ match

  3. Path = /service-a/* → ✅ match

  4. ALB forwards to tg-service-a → instance:8081

  5. Service 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