Я создал API с помощью AWS API Gateway и Lambda, который имеет тот же https://github.com/aws-samples/simple-websockets-chat-app. Но API не работает траст. Я получаю сообщение об ошибке, когда я пытаюсь подключиться. Его сообщение: «Подключение WebSocket к« wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev »не удалось: ошибка во время рукопожатия WebSocket: Неожиданный код ответа: 500»
Мой код подключения
var ws= new WebSocket("wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev");
ws.onopen=function(d){
console.info(d);
}




попробуйте использовать wscat -c wss://b91xftxta9.execute-api.eu-west-1.amazonaws.com/dev в терминале. Это должно позволить вам подключить его. Если у вас не установлен wscat, просто выполните npm install -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. Затем снова отправьте запрос на подключение и отслеживайте журналы API в CloudWatch. В моем случае у меня была следующая ошибка:
Execution failed due to configuration error: API Gateway does not have permission to assume the provided role {arn_of_my_role}
Итак, я добавил Шлюз API к Доверительные отношения моей роли, как уже упоминалось, здесь, и это решило проблему.
Код ответа
500— это HTTP-код дляInternal Server Error... поэтому ваш первый шаг — проверить журналы шлюза API.