我创建了一个应用程序接口由AWS API网关和Lambda是相同的'https://github.com/aws-samples/simple-websockets-chat-app‘。但是API不工作信任。当我尝试连接时,我得到一个错误。它的消息是“到'wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev‘的WebSocket连接失败:WebSocket握手期间出错:意外响应代码: 500”
我的连接代码
var ws= new WebSocket("wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev");
ws.onopen=function(d){
console.log(d);
}
发布于 2020-08-05 21:20:26
尝试将$context.error.validationErrorString和$context.integrationErrorMessage添加到阶段的日志中。
我在日志格式部分添加了一大堆东西,如下所示:
{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp",
"requestTime":"$context.requestTime", "httpMethod":"$context.httpMethod",
"routeKey":"$context.routeKey", "status":"$context.status",
"protocol":"$context.protocol", "errorMessage":"$context.error.message",
"path":"$context.path",
"authorizerPrincipalId":"$context.authorizer.principalId",
"user":"$context.identity.user", "caller":"$context.identity.caller",
"validationErrorString":"$context.error.validationErrorString",
"errorResponseType":"$context.error.responseType",
"integrationErrorMessage":"$context.integrationErrorMessage",
"responseLength":"$context.responseLength" }在早期的开发中,这允许我看到这种类型的错误:
{
"requestId": "QDu0QiP3oANFPZv=",
"ip": "76.54.32.210",
"requestTime": "21/Jul/2020:21:37:31 +0000",
"httpMethod": "POST",
"routeKey": "$default",
"status": "500",
"protocol": "HTTP/1.1",
"integrationErrorMessage": "The IAM role configured on the integration
or API Gateway doesn't have permissions to call the integration.
Check the permissions and try again.",
"responseLength": "35"
}发布于 2019-06-28 04:43:47
尝试在终端中使用wscat -c wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev。这应该允许您连接它。如果您没有安装wscat,只需执行npm install -g wscat即可
发布于 2020-09-03 14:59:55
要获取更多详细信息,请为您的Stages -> Logs/Tracing -> CloudWatch Settings -> Enable CloudWatch Logs启用日志记录。然后,再次发送连接请求,并在CloudWatch中监控您的接口日志。在我的例子中,我有下一个错误:
由于配置错误,
执行失败: API网关无权承担提供的角色{arn_of_my_role}
因此,我将应用编程接口网关添加到我的角色的信任关系中,因为它提到了here,它解决了这个问题。
https://stackoverflow.com/questions/54761176
复制相似问题