Elastic Load Balancing
Developer Guide (API Version 2011-11-15)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Enabling Application-Controlled Session Stickiness

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:

To Enable Application-Controlled Session Stickiness

  1. 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

  2. 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

  1. 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
  2. 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