To server multiple Fargate services from a single ALB, you need to create different target groups (TGs) for them. So, each service will have its own TG, and ALB will forward traffic to respective TGs based on some listener rules.
Since you have Route53, a common choice is to create sub-domains, e.g.: service1.example.com
and service2.example.com
. You associate them as simple Alias A records with the same ALB.
On the ALB you will have single listener (e.g. HTTP 80), with different rules. For example:
- Rule one will be based on
Host header
equal to service1.example.com
, with Action
of Forward
to TG1.
- Rule two will be based on
Host header
equal to service2.example.com
, with Action
of Forward
to TG2.
- Some default rule compulsory (or use 2 as default rule).
And that's it. Any request from the internet directed to service1.example.com
will go to your TG1 which is Fragete service1. Same for requests to service2.example.com
.