Skip to main content
Knowledge Base

How do I enable multiple ecs services to use the same loadbalancer

Answer

Hello, We are using the module available at terraform-aws-service-catalog.git//modules/services/ecs-service to create our ecs services. However, it creates an alb for each and every service in the same ecs cluster. I had a look at the variables.tf, and at a glance I do not see the option to be able to specify an existing loadbalancer. Could you please let me know if there is any workaround where I can have multiple services using the same load balancer. --- <ins datetime="2023-07-27T17:24:35Z"> <p><a href="https://support.gruntwork.io/hc/requests/110378">Tracked in ticket #110378</a></p> </ins>

Hi @sewmiuraj, each service created by the ecs-service module creates a `target_group` for an alb, but not an alb. You can connect those two using a listener such as creating a new `aws_lb_listener`, or you can try using the listener map from the output of the of our alb module as the input for the variable `default_listener_arns` like below: https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/c7b283053fcc46d752ff506f335e67f8311ad211/examples/for-production/infrastructure-live/_envcommon/services/ecs-sample-app-frontend.hcl#L135 https://github.com/gruntwork-io/terraform-aws-service-catalog/blob/c7b283053fcc46d752ff506f335e67f8311ad211/examples/for-production/infrastructure-live/_envcommon/services/ecs-sample-app-backend.hcl#L156C1-L156C88 You'll need to configure the rules in each service so things like the paths are appropriate for each service. Is this helpful with your problem?