Websocket Using Golang Gorilla(Framework) on ECS fargate exposed through ALB.I am getting 404! Works locally though.


Hi I am deploying an app on ECS fargate container as service that used websocket to initiate chat sessions. I am facing some challenges in terms of making it work.

What I made sure before I ask this question: My security groups are allowing all the traffic that is needed for app to work. I have turned on Stickiness in Target group. I also turned on Session Stickiness at Group level. My health check on port 8080(/health) works fine.

I was wondering if I am missing something either in Gorilla framework(some setting or config) or AWS ALB settings that is causing 404.

Looking for help ! Regards Bhanu

1 Answer

Hi Bhanu,

First of all, what you're trying to do is perfectly feasible with the configuration you've mentioned, so don't give up - it's probably a configuration problem somewhere.

Now here are a few things to test/check:

  • WebSocket Support on ALB

Application Load Balancers do support WebSocket traffic, but you need to ensure that the 'Connection' header is set to 'Upgrade' and the 'Upgrade' header is set to 'websocket' during the WebSocket handshake. You can see some header example here

  • WebSocket Path in the Application

As 404 is a NOT FOUND HTTP error, ensure that the WebSocket endpoint path is correctly specified in the ALB listener rules and that it matches the path configured in your Golang application using the Gorilla framework

  • Look at the logs

One thing to try is to connect directly to the WebSocket service of one of your fargate task to bypass the ALB and to rule out any issues with the ALB configuration. If you cannot make it work, check the logs.

If websocket are working from ECS standpoint, then you can enable [ALB access Logs] (https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html) to get more insight into the requests that are reaching the ALB and how they are being handled.

Good luck !

profile pictureAWS
answered 2 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