Skip to content

How to Route Multiple ECS Services Behind a Single ALB Domain Using Different Target Ports

0

Hi, I’m currently running a Proof of Concept (PoC) where multiple workloads are deployed on Amazon ECS behind a single Application Load Balancer (ALB).

Since this setup does not use custom domains or Route 53, both services are accessed through the default ALB DNS name (e.g., my-alb-123456.ap-southeast-1.elb.amazonaws.com).

I would like to confirm the following:

  • Can the ALB forward traffic to multiple ECS services running on different target ports (for example, one service on port 80 and another on port 8080)?
  • Is it valid to use port-based routing in this case, since host-based rules can’t be applied without unique domain names?
  • Are there any best practices or configuration considerations for routing multiple ECS services under one ALB domain in a PoC setup like this?

Thanks

1 Answer
0

Yes, you can definitely route traffic to multiple ECS services running on different target ports using a single Application Load Balancer (ALB) with its default DNS name.

For your port-based routing scenario, you have a couple of approaches:

  1. Multiple Listeners on the ALB: You can configure your ALB with multiple listeners, each listening on a different port. For example:
  • Listener on port 80 routes to ECS service A
  • Listener on port 8080 routes to ECS service B

This way, users would access your services via:

  • my-alb-123456.ap-southeast-1.elb.amazonaws.com:80 for service A
  • my-alb-123456.ap-southeast-1.elb.amazonaws.com:8080 for service B
  1. Path-based Routing: Even without custom domains, you can use path-based routing rules with a single listener:
  • my-alb-123456.ap-southeast-1.elb.amazonaws.com/service-a/* routes to service A
  • my-alb-123456.ap-southeast-1.elb.amazonaws.com/service-b/* routes to service B

For ECS services, the ALB supports dynamic host port mapping, which is particularly useful. For example, if your task's container definition specifies port 80 for a container port and port 0 for the host port, ECS will dynamically choose a port from the ephemeral port range (like 32768-61000). The container is then registered with the ALB as an instance ID and port combination, allowing multiple tasks from a single service on the same container instance.

Best practices for your PoC setup:

  • For services requiring access to multiple load-balanced ports, configure separate listeners for each port
  • Ensure your load balancer subnet configuration includes all Availability Zones where your container instances reside
  • Optimize load balancer health check parameters to speed up deployments
  • If using the awsvpc network mode for your tasks, set the target type to ip instead of instance
  • Use a unique target group for each service to avoid issues during service deployments

This approach works well for a PoC and can be extended later with custom domains if needed.
Sources
Use an Application Load Balancer for Amazon ECS - Amazon Elastic Container Service
Registering multiple target groups with an Amazon ECS service - Amazon Elastic Container Service
Using multiple Elastic Load Balancing listeners - AWS Elastic Beanstalk
How to prepare architecture for 1 public elastic IP and multiple ec2 instances with routing based on port | AWS re:Post

answered a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.