16

I'm trying to get my websockets working with Amazon Web Service and Elastic Beanstalk (ELB).

I set up a proxy protocol according to: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html

I've opened up all inbound traffic to my load balancer and other security groups on all ports, for all IPs.

I also kept the load balancer listerner as HTTP on port 80.

My websocket connection gives the following error when trying to connect on port 80: failed: Error during WebSocket handshake: Unexpected response code: 400

And this error on port 8080: failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Would appreciate suggestions, I'm stuck at this point.

Thanks!

5
  • did you find any solution, i am facing the same problem Commented Jan 29, 2015 at 9:11
  • 2
    github.com/Automattic/socket.io/issues/1846 Commented Feb 15, 2015 at 3:46
  • 2
    Amazon's Elastic Load Balancers do not appear to support web sockets at this time, when setup using HTTP listeners. The suggested work-around is to use a TCP-based listener. See the above link. Commented Feb 15, 2015 at 3:47
  • Do you happen to know if this is possible without a Load Balancer? As in, an EB app with only a single instance? Commented Nov 2, 2020 at 22:26
  • Create a load balancer with single instance then ;) Commented Nov 14, 2020 at 16:27

5 Answers 5

9

After configuring EC2 Security group your application will work with public IP.

But you still will get issue with using EB URL. To solve this issue, you have to change EB configuration.

  1. Go to EB environment page
  2. Configuration
  3. In Load Balancing section change protocol from HTTP to TCP.

Now you can click EB URL.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you happen to know if this is possible without a Load Balancer? As in, an EB app with only a single instance?
4

AWS has launched new Application Load Balancer that supports web sockets. Change your ELB to Application Load Balancer and that will fix your issue.

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

Comments

3

I was also looking for possible workaround for this issue, but it's quite easy irrespective of what platform language you are using to develop websocket program on AWS EC2, as am using Node.js nginx in my case, this should work for all supporting platforms.

Configure Security Group

  1. In the AWS console, open the EC2 tab.
  2. Select the relevant region and click on Security Group.
  3. You should have an elasticbeanstalk-default security group if you have launched an Elastic Beanstalk instance in that region for your app.
  4. click on Actions button at top, and select Edit inbound rules.
  5. here in Type column select All TCP, or you can set some Custom TCP rule as well to listen at your websocket port.

    And that's it!

Note: If something is not working, check the "Events" tab in the Beanstalk application / environments and find out what went wrong.

Comments

3

You should create reverse proxy for Nginx server. You can include this config file in you .ebextensions folder to make Nginx support WS.

Also in the EBS's load balancer configuration change the protocol from HTTP to TCP.

enter image description here

Refer this blog to set up secure WebSocket.

1 Comment

I have A java application with WebSocket How can I configure.
0

This is a very old post but having searched around for answers on this I have found two things you need to do to get websockets on a custom port working with AWS EB.

  1. Under the configuration of your EB environment. Go to Software and add an environment variable there. Make sure this is a case sensitive match with your code.

  2. Again under the configuration of your EB environment. Go to Load Balancer and add the custom port as a listener.

Make sure you save the new listener under the config and on reload it should be routing websocket traffic on a custom port

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.