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

1

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 :-

{endpoint}/_stcore/stream

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 回答
1

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
专家
Uri
已回答 3 个月前
profile picture
专家
已审核 1 个月前
  • 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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则