8

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);
}

1
  • Response code 500 is the HTTP code for Internal Server Error... so your first step is to check the API Gateway logs. Commented Feb 19, 2019 at 9:43

3 Answers 3

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"
}
Sign up to request clarification or add additional context in comments.

1 Comment

I added those context variables and got this errorResponseType: "API_CONFIGURATION_ERROR" which doesn't tell me more about it
2

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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.