12 thoughts on “Rails 5 tutorial chat app – can we deploy it to AWS?

  1. Also faced this problem and was able to fix it by creating a file inside: /etc/nginx/conf.d/ and putting there: *server_names_hash_bucket_size 128;*

    64 bit didn’t help you because the url names became so long so even 64 bit weren’t enough however nginx has weird error message bug keep saying that 64 bit isn’t enough even for 128 bit case.

    • Good to know, thanks.
      For us the problem remained getting the new NGINX config file into the AWS elastic beanstalk pipeline.
      We have now moved on and successfully added Action Cable to the product without issue.

    • Hi Alex, Sorry for the late reply. I think load balancer makes this easier because it handles SSL for you which removes one layer of complexity. Hopefully there are examples somewhere where this has been done successfully and written up.

  2. Hi, I use rails5 ActionCable and Angular. Locally the app works and I tried to deploy it on Amazon with the recommendations that you give in the blog but still get the error. “Firefox can’t establish a connection to the server at ws://env1.sughaj7u8v.us-west-2.elasticbeanstalk.com/cable”. do you have experience with rails5 ActionCable and angular deployment on Amazon?

    • Hi Andrey

      No but the nginx documentation was pretty useful, as was temporarily adding debug logging to the nginx config file: https://easyengine.io/tutorials/nginx/debugging/. Then you can take a look in AWS logs, find the log with whatever name you gave it and see what the nginx config is actually doing. If you do not see any logging then maybe your ws request isnt making it to nginx at all.
      Other places to look for evidence are the puma.log (the production log), and your browser console. Here is the production log line from ActionCable when it is working, including all of the keys & values nginx must supply for this to work :

      Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)

      Hope that helps?

      • Thanks for the reply
        But my mistake was that I had not noticed the error in the log.
        In the study of the logs (/var/app/containerfiles/logs/production.log) I found the error “Request origin not allowed: http://test.sughai5u9v.us-west-2.elasticbeanstalk.com” for its solution, I added “config.action_cable.allowed_request_origins = [/(?:^(http|https):\/\/)?(?:([^.]+)\.)?#{ENV[“domain”]}/]” in production.rb

    • Elastic Beanstalk and a classic ELB (Elastic Load Balancer) doesn’t seem like it will support actioncable (unless you create a completely separated environment to handle the web sockets.
      Since August 2016, AWS started supporting ALB (Application Load Balancer) which should support Web Sockets (hence Action Cable) – reference: https://aws.amazon.com/about-aws/whats-new/2016/08/aws-elastic-beanstalk-supports-application-load-balancer/
      I can’t give much further information, since I needed to set it up a few weeks before they released, so I just changed my app to use a third party service (Pusher), and didn’t try to change it back to Action Cable – I actually quite liked the result of using the third party service.

      • Hopefully if you have the opportunity revisit this you can make ELB work for web sockets. I’m confident it is possible to configure ELB to not get in the way of long-standing TCP connections between clients and your server.
        Maybe look at this: https://blog.jverkamp.com/2015/07/20/configuring-websockets-behind-an-aws-elb/
        Then how you architect your AWS infrastructure will obviously depend on the anticipated need to scale. At the small end a single web server can handle everything: the SSL, and serve https and wws requests (as we are doing). Up from that you might add an ELB; and for larger systems you may want to configure one or more servers to specialize in serving wws requests, probably behind an ALB.

  3. Hey, thanks for a really good tutorial.

    I want to create a application that uses Elasticache instead of a redis server integrated into the EC2 instance. Do you know a step by step procedure to successfully link an Elasticache Redis cluster to an Elastic Beanstalk application in order for ActionCable to work?

    Thanks!

Leave a comment