Back to results for “Amazon ECS (Elastic Container Service)”
AWS › Elastic Load Balancing (ALB, NLB & CLB)

How does path based and host based routing on an Application Load Balancer support directing traffic to different backend services within a single load balancer?

Intermediate

Answer

Path based routing lets you direct requests to different target groups based on the URL path, such as sending requests starting with slash api to one set of servers and slash images to another, while host based routing directs traffic based on the requested hostname, such as routing api.example.com and www.example.com to entirely different target groups, both letting a single Application Load Balancer efficiently serve multiple backend services or microservices without needing a separate load balancer for each one.
aws elbv2 create-rule --listener-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-alb/abc/def --conditions Field=path-pattern,Values='/api/*' --actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:...
Real-world example A company running both its main website and a separate API service uses a single Application Load Balancer with path based routing rules, sending requests to slash api to their API servers while all other requests go to their main website servers.

Common follow-ups: How many routing rules can a single Application Load Balancer listener support?;What is the priority order when multiple routing rules could match the same request?