Listener Rules and Path-Based Routing
Write listener rules on the ALB to route requests to different target groups based on host headers, path patterns, or query strings.
ALB Listeners Explained
An ALB listener is a process that checks for connection requests using a protocol and port you specify (e.g., HTTP on port 80 or HTTPS on port 443). Each listener has one or more rules that determine where to forward requests based on their content.
A listener must have a default rule (the catch-all action when no other rule matches) and can have up to 100 additional rules. Rules are evaluated in priority order (lowest number = highest priority). When a request matches a rule's condition, the corresponding action is applied and no further rules are evaluated.
# Create an HTTP listener on port 80
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789:loadbalancer/app/my-alb/abc123 \
--protocol HTTP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/default-tg/def456Rule Conditions
Listener rules match requests based on conditions. You can combine multiple conditions in one rule (all conditions must match for the rule to apply). Available condition types:
- host-header: matches the
HostHTTP header (e.g.,api.example.com) - path-pattern: matches the URL path (e.g.,
/api/*,/images/*.jpg) - http-header: matches any HTTP header name and value pattern
- http-request-method: matches HTTP methods (GET, POST, DELETE, etc.)
- query-string: matches key-value pairs in the query string
- source-ip: matches client IP CIDR ranges
All lessons in this course
- ALB vs NLB vs GLB: When to Use Which
- Target Groups and Health Checks
- Listener Rules and Path-Based Routing
- SSL Termination and Sticky Sessions