Sticky Sessions for Amazon’s Elastic Load Balancers
| October 17, 2013 | in
One of the great features of Amazon’s Elastic Load Balancers (ELB) – at least in my opinion – is the ability to establish sticky sessions (or session affinity). These allow clients to connect to specific instances in the load-balancer for the life of a session. In typical situations (when you don’t use sticky sessions), calls made to load balancers are routed to whichever instance has the smallest load.
So that is awesome, but what do you do if you only want some calls to be sticky? As it turns out, the stickiness of the ELB is specified per port using the AWS Management Console.
There is a subset of ports that you can configure for your ELB (25, 80, 443, and 1024 through 65535). By adding a second port and making one sticky and one not, we can effectively turn off stickiness by adding the appropriate port number to certain calls.
This is probably not a common use case, and there are other hosting options that would have allowed us to achieve the same goal. However, this was a way we found to quickly make a few calls sticky without significant architecture changes.
The big take-away here should be knowing that when you are setting up and specifying the port configuration of your ELB to specify the stickiness for each. And if you get stuck, AWS has great documentation to help get you through.