Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use application-controlled session stickiness in AWS Elastic Beanstalk?

I am developing a Lift application deployed on AWS Elastic Beanstalk Tomcat 7 container. My application requires sticky sessions when utilizing the Elastic Load Balancer.

Since my application uses the standard servlet stuff, it serves a JSESSIONID cookie to the client. I would like to configure AWS to use application-controlled session stickiness, where given the name of my cookie, it will keep track of the sessions. However, in Elastic Beanstalk Load Balancer configuration, I only see the ability to configure an AWS-managed cookie. I suppose this will work, but I would rather only serve one cookie and have the stickiness coincide with the sessions consistently with the way we have them configured in our application.

While it appears that we can configure application-controlled session stickiness in the EC2 settings associated with my EB instance, the settings we apply get clobbered any time we make changes in the EB console. This isn't terribly surprising behavior, but I would expect that we would soon forget this behavior and accidentally wipe out our settings.

Does anyone know if it is possible to make the stickiness sticky? :)

like image 524
joescii Avatar asked Mar 12 '14 16:03

joescii


1 Answers

Elastic Load Balancer (ELB) supports for application-controlled session stickiness (http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-sticky-sessions.html#enable-sticky-sessions-application). If you want to do this, you can create an .ebextensions scripts to modified the Beanstalk ELB. You can't do this via Beanstalk Web Console.

To configure via .ebextensions, just create a directory named .ebextensions inside your root Beanstalk app and create a file (e.g: 00-load-balancer.config) inside the .ebextensions directory.

The .ebextensions/00-load-balancer.config file could be:

{
  "Resources": {
    "AWSEBLoadBalancer": {
      "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties": {
        "AppCookieStickinessPolicy": [
          {
            "PolicyName": "HttpSessionStickinessPolicy",
            "CookieName": "JSESSIONID"
          }
        ],
        "Listeners": [
          {
            "LoadBalancerPort": 80,
            "Protocol": "HTTP",
            "InstancePort": 80,
            "InstanceProtocol": "HTTP",
            "PolicyNames": [
              "HttpSessionStickinessPolicy"
            ]
          }
        ]
      }
    }
  }
}

The config will modify the ELB to listen port 80 and forward it to a certain EC2 instance port 80 based on HttpSessionStickinessPolicy policy. The HttpSessionStickinessPolicy will do application-controlled session stickiness.

Please refer to AWS Elastic Beanstalk (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-resources.html) and AWS CloudFormation (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb.html) documentation to know more about that.

like image 148
Edward Samuel Avatar answered Oct 24 '22 15:10

Edward Samuel