Google
 

Saturday, February 27, 2016

AWS Elastic Load Balancing session stickiness - Part 2

In my previous post "AWS Elastic Load Balancing session stickiness" I demonstrated the use of AWS ELB  Load Balancer Generated Cookie Stickiness. In this post we'll use application generated cookie to control session stickiness.
To demonstrate this feature, I created a simple ASP.NET MVC application that just displays some instance details to test the load balancing.

Starting from the default ASP.NET MVC web application template, I modified the Index action of the HomeController:



Similar to what I've done in the previous posts using Linux shell scripts, this time I'm using C# code to request instance metadata from the http://169.254.169.254/latest/meta-data/ URL then I store the host name and IP address in the ViewBag object and display them in the view:


I deployed the application to two EC2 Windows 2012 R2 instances. As expected, using the default ELB settings, requests will be routed randomly to one of the instances. This can be tested by looking at the host name and IP displayed in the response.

Looking to the request and response cookies, we can find the asp.net session cookie added:

To configure stickiness based on the ASP.NET_SessionId cookie, edit the stickiness configuration and enter the cookie name:


Checking the cookies, we find that ELB generates a cookie named "AWSELB". As documented: "The load balancer only inserts a new stickiness cookie if the application response includes a new application cookie."


Now the browser will send back both the session and ELB cookies:

Still my preference for maintaining session state is to use a distributed cache service like Redis or even SQL server. Because in case an instance goes down or is removed from an auto-scaling the user will lose his session data in case it's stored in memory.

12 comments:

Tanishka said...

Really an awesome post. I wondered by reading this blog post. Thanks a lot for posting this unique post which you have shared with us. Keep on posting like this exclusive post with us.

Hadoop Training in Chennai

Anu Sri said...

Excellent post !. I learned lot of information. Thanks!

php training in chennai

Arjun Rishi said...

Great article. Thanks for sharing such a useful post.

ppc training in chennai

Anu Sri said...

Nice post. glad to find your blog. Thanks for sharing.

web design training institute in Chennai

Andrew Son said...

Hadoop is a framework which has four classifications in it. Each has different properties and apache hadoop is an open source software framework. It is used for distributed processing and distributed storage. It use handle large set of data and information.
Regards,
Big Data Training in Chennai | Hadoop Training in Chennai

Nivedageorge said...

Great article, Happy to visit your blog. Keep sharing such a useful post.

SEO Training in Kodambakkam

jhansi joe said...

Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
SEO Training

Jhon Mick said...

Php is abbreviated as Hypertext preprocessor. Learn php and its dynamic working behavior is really interesting.
PHP Training in Chennai | PHP Course in Chennai

Anonymous said...

Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post. java training in jalandhar

Anonymous said...

Nice post. Thanks for the shearing valuable information. I really fiend this type blog. Special thanks to writer. web designing jalandhar

reginald surict said...

Thanks for sharing this post. You can also download apps to spy on your spouse.

for IT the said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.