- Newest
- Most votes
- Most comments
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:
- 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
- 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
awsvpcnetwork mode for your tasks, set the target type toipinstead ofinstance - 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
Relevant content
- asked 10 months ago
- asked a year ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated a year ago
