Is there a way to Implement WebSockets on AWS’s ELB (Elastic Load Balancer)

0

I am trying to experiment to implement my website with an Amazon ELB (Elastic Load Balancer).

I was successfully able to implement the Web part using an HTTPS-based Elastic load balancer, however, my website uses Web Sockets for the Chat session, which seems to be an issue on that to get it working.

WSS based socket running on a different port like 6400, it seems to be error out within the ajax request to chat port with "xmlhttprequest" saying "Access-Control-Allow-Origin" is set to same site.

Access to XMLHttpRequest at 'https://www.example.com:5000/socket.io/?EIO=3&transport=polling&t=N4gTtJ6' from origin 'https://www.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

If we take out the ELB this works fine, however if we enable the ELB it seems to be blocking the WSS port or requests for some reason saying above error.

The webserver is Nginx and Chat runs on Express module engine using NodeJS, on Centos 7.4

mahen3d
asked 4 years ago17844 views
3 Answers
2

ALBs support websockets (https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/)

ALB provides native support for WebSocket via the ws:// and wss:// protocols.

NLBs support websockets (https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html#listener-configuration)

You can use WebSockets with your listeners.

Obviously, you need to have a listener/target group on the websocket port. Websockets should be inherently stickly (at least on the alb https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html.

WebSockets connections are inherently sticky. If the client requests a connection upgrade to WebSockets, the target that returns an HTTP 101 status code to accept the connection upgrade is the target used in the WebSockets connection. After the WebSockets upgrade is complete, cookie-based stickiness is not used.

answered 4 years ago
0

I confront the same issue with application load balancer. ALB blocks the websocket connection. It works fine without ALB (with direct access to IP). I enabled the stickiness of the target group. How can we use websocket with ALB?

nemy
answered 2 years ago
0

I have an ALB that has 1 target group that has 3 instances. I need to subscribe on the socket on ALL 3 instanses via an ALB, because IDK from where the data will come (i use the kafka and send the data via the socket).

How can i achive this ? For now i subscribed only on one of them, and i lost some data

Alex
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions