Web Apps: WebSockets with AWS Elastic Load Balancing

  • October 28, 2014

Amazon Web Service (AWS) Elastic Load Balancing (ELB) is widely used to build highly available and highly scalable architectures. Nowadays, ELB is as common as EC2 is for many customers using AWS. And, Elastic Load Balancing supports the following protocols: HTTP, HTTPs, TCP and TCPs.

WebSocket is a protocol providing full-duplex communication channels over a single TCP connection. You can read more about WebSockets here.

For web applications, we use HTTP or HTTPS protocols with ELB for load sharing. But, AWS ELB with HTTP or HTTPS protocols doesn’t support the WebSockets. Your WebSockets communication gets blocked at ELB. It doesn’t pass through to the backend app servers. There is no official information from AWS as they support the WebSockets with HTTP and HTTPs protocols.

There are alternatives for ELB, such as HAProxy. But, with autoscaling, it’s not easy to dynamically add instances to HAProxy and remove them when scaling down occurs.

There is a workaround in using ELB without compromising the WebSockets. Use TCP as a Load Balancer and Proxy protocol while creating a Load Balancer. ELB with TCP protocol supports the WebSockets. We have successfully implemented this for our customers.

Screenshot of load balancing with AWS ELB
If you have an SSL certificate, then deploy it at the app server level. This way, ELB behaves as just a proxy and passes through all the communication as-is to the backend. The only downside with the procedure is that you can’t terminate the HTTPS at the Load Balancer level. But, this doesn’t compromise your data security because all of the communication from the browser to the app server is encrypted if you deploy SSL at the app server.

There you have it. A quick run-through in regard to WebSockets with AWS Elastic Load Balancing

If you have any comments or questions, let us know! Share them with us in the comments section below.

Get Started with AWS

Receive AWS tips, DevOps best practices, news analysis, commentary and more. Sign up for our blog here and set your topic and frequency preferences. Or, download our guide on getting started with AWS, establishing a secure AWS enterprise architecture with Flux7 Landing Zones.

Subscribe to our blog


Related Blog Posts