5

I created an API by AWS API Gateway and Lambda that is same 'https://github.com/aws-samples/simple-websockets-chat-app'. But the API not working trust. I get an error when i try to connect. Its message is "WebSocket connection to 'wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev' failed: Error during WebSocket handshake: Unexpected response code: 500"

My Connection Code

var ws= new WebSocket("wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev");
ws.onopen=function(d){
 console.log(d);
}

3 Answers3

4

Try adding $context.error.validationErrorString and $context.integrationErrorMessage to the logs for the stage.

I added a bunch of stuff to the Log Format section, like this:

{ "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" }

In early development this allowed me to see this type of error:

{
"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"
}
warrens
  • 1,661
  • 18
  • 16
  • I added those context variables and got this errorResponseType: "API_CONFIGURATION_ERROR" which doesn't tell me more about it – Jun May 20 '23 at 00:10
1

try using wscat -c wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev in a terminal. This should allow you to connect it. If you don't have wscat installed, just do a npm install -g wscat

1

To get more details, enable logging for your API: Stages -> Logs/Tracing -> CloudWatch Settings -> Enable CloudWatch Logs. Then, send a connection request again and monitor your API logs in CloudWatch. In my case, I had the next error:

Execution failed due to configuration error: API Gateway does not have permission to assume the provided role {arn_of_my_role}

So, I added API Gateway to my role's Trust Relationships, as it's mentioned here and it fixed the problem.

nikiforovpizza
  • 487
  • 1
  • 7
  • 13