Socket.io Websockets on a TCP configured Amazon Elastic Load Balancer

amazon-web-services, node.js, socket.io, websocket

Solution

You can now use the new application load balancer recently launched by AWS.

Just replace the ELB(now called Classic load balancer) with the ALB (Application load balancer) and enable sticky sessions.

ALB supports Web sockets. This should do the trick.

https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/

http://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html

Problem

I'm planning to set up a group of NodeJS application servers running Socket.io on EC2, and I'd like to use the Elastic Load Balancer to spread load between them. I know ELB doesn't support Websockets out of the box, but I can use the setup described here in Scenario 2. As described in the blog post, though, I notice that this setup offers no session affinity or source IP info: We can not have Session Affinity nor X-Forward headers with this setup because ELB is not parsing the HTTP messages, so its impossible to match the cookies to ensure Session Affinity nor Inject special X-Forward headers. Will Socket.io still work under these circumstances? Or is there another way to have a set of Socket.io app servers behind a load balancer with SSL? EDIT: Tim Caswell talks about doing this already here. Are there any posts explaining how to set this up? Again there's no session stickiness here, but things seem to be working fine. As an aside, are sticky sessions actually necessary with websockets? Does information travel as new and separate requests or is there only one request + connection that all the information moves along?

Original source

Related problems