Amazon web services AWS API网关WebSocket连接错误
我通过AWS API网关和Lambda创建了一个API,它是相同的“”。但是API不起作用。我尝试连接时出错。它的消息是“WebSocket连接到”wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev'失败:WebSocket握手期间出错:意外响应代码:500' 我的连接代码Amazon web services AWS API网关WebSocket连接错误,amazon-web-services,websocket,aws-api-gateway,Amazon Web Services,Websocket,Aws Api Gateway,我通过AWS API网关和Lambda创建了一个API,它是相同的“”。但是API不起作用。我尝试连接时出错。它的消息是“WebSocket连接到”wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev'失败:WebSocket握手期间出错:意外响应代码:500' 我的连接代码 var ws=新的WebSocket(“wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev");
var ws=新的WebSocket(“wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev");
ws.onopen=函数(d){
控制台日志(d);
}
尝试使用wscat-cwss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev 在终点站。这应该允许您连接它。如果没有安装wscat,只需执行npm安装-g wscat尝试将$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"
}
要获取更多详细信息,请为您的API启用日志记录:
Stages->Logs/Tracing->CloudWatch Settings->enable CloudWatch Logs
。然后,再次发送连接请求并在CloudWatch中监视API日志。在我的例子中,我犯了下一个错误:
由于配置错误,执行失败:API网关无权承担提供的角色{arn_of_my_role}
因此,我在角色的信任关系中添加了API网关,正如前面提到的,它解决了这个问题。响应代码
500
是内部服务器错误的HTTP代码。。。因此,第一步是检查API网关日志。