0
votes

I'm a little confused when I'm trying to use the new application elb from aws. I would like to configure multiple listeners for my elb:

1) Would I need a different target group for every listener?

2) If I just have one server behind the elb, does it then need to be added to every target group?

I'm confused because creating the elb in the console allows configuring of multiple listeners in one step, but in the next step only allows creation of a single target group.

2

2 Answers

3
votes

A target group can contain 1 or more server instances.

A single server instance can be in one or more target groups.

A target group can be used by more than one listener.

So for example in your scenario you could have a single server, in a single group. that is used by multiple listeners. Or you could have a single server in multiple groups, each used by one or more listeners.

2
votes

Yes you can create additional listeners on an ALB (ELBv2) and reference the same and / or different Target Groups.

ALBs can have multiple listeners as you may want to listen on http and https and you can reference the same TargetGroup twice as in some use cases the application instances in the target group will be able to handle both.

More advanced usages might make use of ALB Listener Rules and even more listeners / target groups listening on the same or different ports and operating the same or different protocols to other listeners in your ALB. However don't worry about this for now as it doesn't come up in your use case.

I think your confusion is due to the "wizard-ry" of the AWS console. After you create your ALB you will be able to add additional listeners to it. Just create the first one during the create new load balancer process and then afterwards:

  • Select your new ALB in the AWS Console (EC2/Load Balancers)
  • In the detail panel for the selected Load Balancer select the "Listeners" tab and click the "Add Listener" button.
  • Then select the protocol, port and target group then click save and you're done!

Afterthoughts:

I am not sure why you would have only a single server in your TargetGroup/s as it is not a good design practice to make use of a single instance in this example (even if your Auto Scaling Groups's launch configuration spans multiple AZs for resilience) however, if that is what you choose to do in your configuration it will work. :)

You haven't mentioned an Auto Scaling Group in your solution. In my opinion you should consider adding one for your instance/s and also check out the very nice integration between the ASG and the TargetGroup which allows for automatic addition and subtraction of instances in the TargetGroup by use of Life Cycle Hooks.