| Did this page help you? Yes No Tell us about it... |
The load balancer uses a special cookie to associate the session with the original server that handled the request, but follows the lifetime of the application-generated cookie corresponding to the cookie name specified in the policy configuration. The load balancer only inserts a new stickiness cookie if the application response includes a new application cookie. If the application cookie is explicitly removed or expires, the session stops being sticky until a new application cookie is issued.
In this example, you configure a load balancer for session stickiness when the life of the session follows that of an application-generated cookie. Before you get started, be sure you've done the following:
Created a load balancer with Elastic Load Balancing. For information on how to set up a HTTPS/SSL load balancer with the AWS Management Console, command line interface (CLI), or Query API, see Creating a Load Balancer With SSL Cipher Settings and Back-end Server Authentication. To learn how to set up a HTTP load balancer with the AWS Management Console, see Get Started with Elastic Load Balancing.
Installed the Elastic Load Balancing tool that you plan to use to perform load balancing tasks. You can create a session stickiness policy using the AWS Management Console, the command line interface (CLI) or the Query API. For information on installing the command line interface (CLI) or the Query API, see Get Set Up with Elastic Load Balancing Interfaces.
For detailed descriptions of the Elastic Load Balancing commands, see the Elastic Load Balancing Quick Reference Card.
For detailed descriptions of the policy configuration Query API for application-generated HTTP cookies, go to CreateAppCookieStickinessPolicy in the Elastic Load Balancing API Reference
To Enable Application-Controlled Session Stickiness
Call CreateAppCookieStickinessPolicy with the following
parameters to create an application-generated cookie stickiness policy.
LoadBalancerName = my-load-balancer
PolicyName = my-app-cookie-lb-policy
CookieName = my-cookie
Call SetLoadBalancingPoliciesOfListener with the following parameters to enable session stickiness for a load balancer using the
my-load-balancer policy.
LoadBalancerName = my-load-balancer
LoadBalancerPort = 80
PolicyNames = my-app-cookie-lb-policy
To Enable Application-Controlled Session Stickiness
Use the elb-create-app-cookie-stickiness-policy command to create a load application-generated cookie stickiness policy .
PROMPT>elb-create-app-cookie-stickiness-policy my-load-balancer -p my-app-cookie-lb-policy -c my-cookie
Elastic Load Balancing returns the following:
OK-Creating App Stickiness Policy
Use the elb-set-lb-policies-of-listener command to enable session stickiness for a load balancer using the my-load-balancer.
PROMPT>elb-set-lb-policies-of-listener example-lb --lb-port 80 --policy-names my-app-cookie-lb-policy
Elastic Load Balancing returns the following:
OK-Setting Policies