Can we use one ALB with AWS ECS Fargate?

4.5k views Asked by At

I am having a bunch of micro services running in AWS ECS fargate with ALB and Route53.Each micro service has an ALB with Route53.

Is there any kind of possibility where I can use only one ALB for all the microservices and route to their respective Route53 paths??

Here, I am not using EKS. Using AWS ECS Fargate.

1

There are 1 answers

8
Marcin On BEST ANSWER

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:

  1. Rule one will be based on Host header equal to service1.example.com, with Action of Forward to TG1.
  2. Rule two will be based on Host header equal to service2.example.com, with Action of Forward to TG2.
  3. 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.