Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon ELB - Sticky session lost of cookie

I have a Node.js app on Elastic Beanstalk running on multiple ec2 instance behind a load balancer(elb).

Cause of the need of my app, i had to activate the session stickiness. I activated the "AppCookieStickinessPolicy" using my custom cookie "sails.sid" as reference.

The problem is that my app need this cookie to work proprely, but as the moment I activate the session stickness (via Duration-Based Session Stickiness or in my case : Application-Controlled Session Stickiness), the headers going to my server are modified and I lost my custom cookie, who is replaced by the AWSELB (amazon ELB) cookie.

How can I configure the loadbalancer to not replace my cookie?

If I understood well, the AppCookieStickinessPolicies must keep my custom cookie but it's not the case. I am doing wrong somewhere?

Thanks in advance

Description of my load balancer :

{
    "LoadBalancerDescriptions": [
        {
            "AvailabilityZones": [
                "us-east-1b"
            ],

            ....

            "Policies": {
                "AppCookieStickinessPolicies": [
                    {
                        "PolicyName": "AWSConsole-AppCookieStickinessPolicy-awseb-e-y-AWSEBLoa-175QRBIZFH0I8-1452531192664",
                        "CookieName": "sails.sid"
                    }
                ],
                "LBCookieStickinessPolicies": [
                    {
                        "PolicyName": "awseb-elb-stickinesspolicy",
                        "CookieExpirationPeriod": 0
                    }
                ],
                "OtherPolicies": []
            },
            "ListenerDescriptions": [
                {
                    "Listener": {
                        "InstancePort": 80,
                        "LoadBalancerPort": 80,
                        "InstanceProtocol": "HTTP",
                        "Protocol": "HTTP"
                    },
                    "PolicyNames": [
                        "AWSConsole-AppCookieStickinessPolicy-awseb-e-y-AWSEBLoa-175QRBIZFH0I8-1452531192664"
                    ]
                }
            ]

            ....

        }
    ]
}
like image 597
Thomas Leclercq Avatar asked Jan 12 '16 08:01

Thomas Leclercq


People also ask

Does AWS ELB support sticky session?

If you are using multiple layers of Application Load Balancers, you can enable sticky sessions across all layers with application-based cookies. However, with duration-based cookies, you can enable sticky sessions only on one layer, because AWSALB is the only name available.

What are the issues with sticky session?

A server can become overloaded if it accumulates too many sessions, or if specific sticky sessions require a high number of resources. This could result in your load balancer having to shift a client to a different server mid-session, resulting in data loss.

What is AWS ELB stickiness?

August 2021 (document history) Stickiness is a term that is used to describe the functionality of a load balancer to repeatedly route traffic from a client to a single destination, instead of balancing the traffic across multiple destinations.

What is cookie persistence in load balancer?

That technique is called cookie-based persistence. Rather than rely on the SSL/TLS session ID, the load balancer would insert a cookie to uniquely identify the session the first time a client accessed the site and then refer to that cookie in subsequent requests to persist the connection to the appropriate server.


1 Answers

The sticky session cookie set by the ELB is used to identify what node in the cluster to route request to.

If you are setting a cookie in your application that you need to rely on, then expecting the ELB to use that cookie, it is going to overwrite the value you're setting.

Try simply allowing the ELB to manage the session cookie.

like image 183
chris Avatar answered Oct 27 '22 00:10

chris