stickiness in elb listener vs elb target group

Viewed 308

I have been looking at the terraform elastic load balancer resources and noticed that there are stickiness resource blocks inside a listener (aws_lb_listener > default_action > forward > stickiness ) and target group .

Is there any difference between the two if one is forwards requests to the associated target group?

should one configure them both in similar ways if you want that sticky behaviour ?

is it better to configure stickiness on the target group instead?

1 Answers

I had to go into the AWS console and look at the Load Balancer settings to see what was going on with this. Apparently you can add multiple target groups to a single listener, and the listener will spread the requests among all target groups. As part of spreading the traffic among multiple target groups you can enable a "group stickiness" setting that will cause all traffic from one source to always go to the same target group.

I had never noticed the ability to add multiple target groups to a listener before, and I had to do some searching to find any documentation on this feature. It was apparently announced via this blog post, which links to some documentation here.

So to summarize, the aws_lb_listener setting is a separate stickiness setting that only applies to weighted target groups, and "sticks" the traffic to a specific target group, not individual targets. The aws_lb_target_group stickiness setting "sticks" the traffic to an individual target.

Unless you are using multiple weighted target groups, you will want to always use the aws_lb_target_group setting for session stickiness. If you are using weighted target groups and also need sticky sessions then you would enable it in both places. If you don't normally need sticky sessions, but you do want to "stick" to a specific target group for some reason, like in a blue-green deployment scenario, then you would only enable it at the listener level.

Related