在AWS ApiGateway中设置基本WebSocket模拟
我正在尝试在AWS ApiGateway中设置一个非常简单的WebSocket模拟。但是,我每次尝试都会出现一个错误:在AWS ApiGateway中设置基本WebSocket模拟,websocket,aws-api-gateway,Websocket,Aws Api Gateway,我正在尝试在AWS ApiGateway中设置一个非常简单的WebSocket模拟。但是,我每次尝试都会出现一个错误: 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 (
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
请求
所有授权和API密钥都被禁用。没有设置请求模板或集成响应,因为我不需要它们。同样,目标是能够有一个可以连接到的哑WebSocket
然而,每当我尝试连接到它时,我都会收到一个500错误,上面有关于状态代码的错误日志
WebSocket connection to 'wss://redacted.execute-api.us-east-1.amazonaws.com/prod' failed: Error during WebSocket handshake: Unexpected response code: 500
通过使用以下来源(如下),我能够获得一个快速而松散的AWS API网关连接示例,该示例使用带有web套接字的模拟端点进行工作。我相信这可以被更深入地挖掘出来,以便更好地理解不同的请求/响应正文消息和代码
$request.body.message
作为路由选择表达式$connect
路线200
,输入模板:{“statusCode”:200}
,然后单击保存按钮。
$default
路由
$disconnect
路线,请对此特定路线重复步骤7-13。
$disconnect
路由后,请在路由窗格下选择$default
路由。
$connect
和$disconnect
创建集成请求的方法相同(步骤7-11)$default
下的集成响应,我们将设置的路由响应与$connect
和$disconnect
略有不同,因为这两条路由的响应实际上在各自的集成响应中引用了$default
响应200
,输入模板:{“statusCode”:200,“connectionId”:“$context.connectionId”}
,然后单击保存按钮。
{“connectionId”:“$context.connectionId”}
已添加到响应负载中,以显示如何在响应中使用变量来表示连接的实际值wss:///######。执行api.us-east-1.amazonaws.com/Test
)wscat
,我现在可以连接到我的WebSocket URL(请参阅下面安装wscat的源代码):wscat-c wss://######。执行api.us-east-1.amazonaws.com/Test
干杯非常详细,谢谢。我相信第13点。有点误导,因为它没有引用$default路由,但它是$default键。感谢您的分步指导!对于获得一个良好的起点有很大帮助。我必须在集成请求中删除statusCode属性中的引号,以获得正确的匹配:(它无法生成和回滚。可能与角色有关。我试图为ApiGateway指定一个角色以登录CloudWatch,但也未能说明该角色不正确或无法应用。我对AWS很陌生,这个错误有意义吗?修复了它,我的角色似乎没有根据和aft建立正确的信任关系呃,它没有POS的权限