Hi.
I have a question regarding ECS services that expose multiple ports. Because as it seems the second target group does not have any affiliation to the ECS service or the hosts that form the ECS cluster.
Following scenario:
A service exposes two ports 1234 and 5678.
Usually you would configure everything that is needed for the alb, first for port 1234 and then for 5678
- aws_alb_target_group for port 1234
- aws_alb_target_group for port 5678
- aws_alb_listener for port 1234
- aws_alb_listener for port 5678
- aws_alb_listener_rule for port 1234 it is /something
- aws_alb_listener_rule for port 5678 it is /somethingelse
- aws_ecs_task_definition for the service
and now it starts to get a little bit confusing.
As you define the aws_ecs_service "exampleService" you define the load_balancer section.
This section only allows one target_group_arn and one port.
Lets assume I chose the target group for port 1234
This affiliation always works, but somehow it is not clear how to associate the second target group with the port 5678 to the same service definition for "exampleService"
It is not possible to add a second load balancer target group within the service definition.
I have also considered to use the "alb target group attachment" but within this definition I only have the option to attach instance ids (which is not possible to get due to the auto scaling group where the ECS cluster is spawned), or, as the documentation also states, to associate a container ID.. And here it starts to get confusing.
The service definition provides an ID but is this the same ID that will be needed here? The documentation is a little unclear here?
The Problem is that without attaching the service to the second target group the second target group often fails due to missing "hosts" or information where to health-check to.
Is there a way to associate multiple target groups to one service definition?
Thanks for the help.
BR
Stefan