I have a node.js application server running on port 80 and I recently added realtime messaging through Primus websockets transformer on port 9001.
It works well in single instance. I deployed the messaging to Beanstalk environment with the following configuration.
AWS Elastic Beanstalk
Platform version v2.0.0
Nodejs version v0.12.6
Primus version v4.0.5
- Port 9001 is added to the security group of the instance as shown in the screenshot.
- Proxy server is set to "none" in configuration options.
- TCP Listener is added in the Elastic Load Balancer configuration.
- Proxy-Protocol is enabled as mentioned in the aws documentation.
- Added proxywrap to the primus server configuration.
But the client requests doesn't reach the instance and connection timed out. Has anyone used primus with websockets behind AWS ELB? Please let me know the configuration which enables websockets communication behind Elastic Beanstalk.
You need to do two things
Increase idle timeout on ELB
On EC2 dashboard, reach for Load Balancer settings and open the Description tab for your load balancer. Look for the setting "Idle timeout", type something like "600" (for 10 minutes)
Ping periodically
Implement a WS ping every 5 minutes (or other, but need to be lower than the idle timeout on ELB). If primus doesn't have support on its API, implement yourself sending of a dummy message to client.
I managed to get websockets (https://github.com/websockets/ws) working on both port 80 and 8080 on ELB with the configurations below. And thats without enabling Proxy-Protocol.
Security group:
Load balancer listeners:
Container options:
Load balancer: