Websocket requests begin with an HTTP connection before being sent to websockets. Theoretically, if you can include a cookie in this initial HTTP request, then the sticky features of the ELB session will allow you to direct websites to specific EC2 instances. However, your websocket client may not support this.
The preferred solution would be to make your EC2 stateless instances. Store the websocket session data in AWS Elasticache (either Redis or Memcached) and then incoming connections will be able to access the session no matter which EC2 instance is used.
The advantage of this solution is that you remove the dependency on individual instances of EC2, and your application will scale and better deal with errors.
If the ELB has too many inbound connections, then it should scale automatically. Although I can not find a link to this. ELBs are relatively slow on a scale of minutes, not seconds, if you expect bursts of traffic, then AWS can preheat more ELB resources for you. This is done through support requests.
In addition, the coefficient in the ELB connection timeout. By default, it is 60 seconds; it can be increased using the AWS console or API. Your application needs to send at least 1 byte of traffic before the timeout, or ELB will disconnect the connection.
Steve E.
source share