AWS API Gateway WebSocket的自定义终端节点路径 [英] Custom endpoint path for AWS API Gateway WebSocket
问题描述
我用Websocket协议创建了一个API网关. 部署API后,我将获得一个WebSocket URL和一个连接URL.
I have created an API Gateway with Websocket protocol. After I deploy the API, I get a WebSocket URL and a connection URL.
例如
WebSocket URL:wss://xxxx.execute-api.us-west-2.amazonaws.com/test
WebSocket URL: wss://xxxx.execute-api.us-west-2.amazonaws.com/test
连接URL:https://xxxx.execute-api.us-west-2.amazonaws.com/test/@connections
现在一切都很好,我能够连接到API,并发送和接收消息. 但是,当我尝试访问其他路径时,出现HTTP 403错误.
Now everything is fine, I am able to connect to the API, and send and receive messages. But when I try to access a different path, I get an HTTP 403 error.
例如如果我尝试连接到wss://xxxx.execute-api.us-west-2.amazonaws.com/test/some/path
,我收到403错误.
e.g. If I try to connect to wss://xxxx.execute-api.us-west-2.amazonaws.com/test/some/path
, I get 403 error.
是否可以以这样的方式配置API网关:它接受与所有路径的连接并在路径上传递,即在我的情况下,将/some/path
传递给$connect
路由处理程序?
Is it possible to configure API gateway in such a way that it accepts connections to all paths and passes on the path, i.e. /some/path
in my case, to the $connect
route handler?
推荐答案
AWS尚不支持.在此处查看文章和评论 https://medium.com/@ lancers/using-parameter-mapping-in-websocket-api-67b414376d5e
This is not yet supported by AWS. See the article and comments here https://medium.com/@lancers/using-parameter-mapping-in-websocket-api-67b414376d5e
有一个使用其他服务器的解决方法,本文的作者提出以下建议: 您可以将自己的服务器接受带有路径参数的URI,然后返回302,以使用查询字符串将客户端重定向到WebSocket API端点.
There is a workaround with using an additional server, author of the article proposes the following: you may put your own server that accepts an URI with path parameters, then return 302 to redirect the client to the WebSocket API endpoint with query string instead.
这篇关于AWS API Gateway WebSocket的自定义终端节点路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!