How to establish switching from Http to websocket protocol in API Gateway


We have deployed the streamlit application with nginx reverse proxy in the ECS Fargate service ,and we are using ALB for load balancing and the routes are exposed in API gateway which is using a HTTP protocol, but the application is not loading ,we think it is not able to perform switching from http to websocket :-


locally we get the response with status 101 switching protocols but in the api gateway we do not know how to switch, request header desired response:- desired response

also this header:-Upgrade:websocket

1 Answer

You can't use API Gateway as a websocket proxy between a client and a backend (the Fargate cluster in your case). The gateway does not support this.

API Gateway does support websockets, but the connection is maintained between the client and the gateway itself. All messages it receives on the connections are forwarded to the backend using regular HTTP requests. Similarly, when the backend wants to send a message to the client, it sends an HTTTP request to the special endpoint in the gateway so that the gateway forwards the message to the client.

profile pictureAWS
answered 2 months ago
profile picture
reviewed 21 days ago
  • Thanks Uri for the response ,Can u shed some light on what could be the right way to go about this.

  • If you need a websocket all the way to backend, expose the ALB directly to the client, without an API Gateway.

  • Hi Uri ,thanks for the response, we have a common private ALB for multiple services within a VPC... we can't change the architecture for a singe service.. can u suggest any other solution

  • If you need a websocket all the way to your backend, you options are to expose the ALB directly (and it can be a new ALB, just for that service, fronting the same cluster), or use a Global accelerator to access the private ALB.

  • Thanks. This was helpful for my case. I cannot find the AWS document explaining that how API Gateway connects the client and the backend in different way, thou. They only offered the best practice of the Websocket API Gateway architecture using VPC Link.

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