在 AWS ApiGateway 中设置基本的 WebSocket 模拟 [英] Setup a basic WebSocket mock in AWS ApiGateway
问题描述
我正在尝试在 AWS ApiGateway 中设置一个非常简单的 WebSocket 模拟.但是,我尝试过的每一次尝试都会给我一个错误:
I am trying to setup an extremely simple WebSocket mock within AWS ApiGateway. However, every attempt I've tried gives me an error:
13:36:52 (X33uOGUfIAMFq7w=) Extended Request Id: X33uOGUfIAMFq7w=
13:36:52 (X33uOGUfIAMFq7w=) Verifying Usage Plan for request: X33uOGUfIAMFq7w=. API Key: API Stage: redacted/prod
13:36:52 (X33uOGUfIAMFq7w=) API Key authorized because route '$connect' does not require API Key. Request will not contribute to throttle or quota limits
13:36:52 (X33uOGUfIAMFq7w=) Usage Plan check succeeded for API Key and API Stage redacted/prod
13:36:52 (X33uOGUfIAMFq7w=) Starting execution for request: X33uOGUfIAMFq7w=
13:36:52 (X33uOGUfIAMFq7w=) WebSocket Request Route: [$connect]
13:36:52 (X33uOGUfIAMFq7w=) Client [UserAgent: null, SourceIp: redacted] attempts to connect to WebSocket API [redacted].
13:36:52 (X33uOGUfIAMFq7w=) Execution failed due to configuration error: statusCode should be an integer which defined in request template
13:36:52 (X33uOGUfIAMFq7w=) Client [UserAgent: null, SourceIp: redacted] failed to connect to API [redacted].
据我所知,我遵循了最基本的配置.我不需要任何响应或模板,只需要一个简单的 WebSocket 连接,它允许我连接到它而不做任何事情,或者可能最终用 pong
响应 ping
请求.
As far as I can tell, I've followed the most basic configuration possible. I do not need any responses or templates, just simple a WebSocket connection that allows me to connect to it and do nothing, or perhaps respond to ping
requests with a pong
eventaully.
禁用所有授权和 API 密钥.没有设置请求模板或集成响应,因为我不需要它们.同样,我们的目标是能够拥有一个可以连接的愚蠢的 WebSocket.
All authorizations and API keys are disabled. No request templates or integration responses are setup since I do not need them. Again, the goal is to just be able to have a dumb WebSocket that can be connected to.
但是,每当我尝试连接到它时,我都会收到 500 错误,上面有关于状态代码的错误日志.
However, whenever I try to connect to it, I get a 500 error with the error logs from above about a status code.
WebSocket connection to 'wss://redacted.execute-api.us-east-1.amazonaws.com/prod' failed: Error during WebSocket handshake: Unexpected response code: 500
推荐答案
通过使用以下资源(如下),我能够得到一个快速而松散的示例 AWS API Gateway 连接使用带有 Web 套接字的 MOCK 端点.我相信这可以被清除更多,以更好地理解不同的请求/响应正文消息和代码..
Using the following sources (below), I was able to get a quick and loose example AWS API Gateway connection working use MOCK endpoints with web sockets. I'm sure this can be flushed out more to provide an even better understanding of different request/response body messages and codes..
- 首先,转到 API Gateway,点击创建 API
- 对于选择协议,选择WebSocket
- 为 API 命名,并使用示例
$request.body.message
作为路由选择表达式 - 点击创建 API 按钮
- 从侧窗格中选择新 API,然后单击路由
- 选择
$connect
路线 - 在路线概览下,选择端点的模拟单选按钮
- 对于请求模板,输入一个表达式(例如使用 200).
- 对于模板密钥,输入一个密钥(例如使用 200)
- 对于有关直通行为的弹出窗口,选择否,暂时使用当前设置
点击Template Key
200
,然后输入一个模板:{"statusCode" : 200}
然后点击保存按钮.
- First, go to API Gateway, click Create API
- For Choose the protocol, select WebSocket
- Give the API a name, and use the example
$request.body.message
for the route selection expression - Click the Create API button
- Select the new API from the side pane, and click Routes
- Select the
$connect
route - Under Route overview, select the Mock radio button for endpoint
- For the Request Template, enter an expression (using 200 for example).
- For Template Key, enter a key (using 200 for example)
- For the popup window on passthrough behavior, select No, Use Current Settings for now
Click on the Template Key
200
, and enter a template:{"statusCode" : 200}
and then click the Save button.
选择路由概览返回$connect
概览页面,然后选择添加集成响应 按钮
创建$default的响应键,它将引用Routes下的$default
路由>
Create a response key of $default, which will reference the $default
route under Routes
对于 $disconnect
路线,请为此特定路线重复步骤 7 - 13.
来源:
https://forums.aws.amazon.com/thread.jspa?threadID=299642&tstart=0
这篇关于在 AWS ApiGateway 中设置基本的 WebSocket 模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!