How can I troubleshoot API Gateway WebSocket API connection errors?
Last updated: 2022-11-17
I tried to connect to my Amazon API Gateway WebSocket API but I received errors. How do I troubleshoot my WebSocket API connection?
API Gateway WebSocket API connection errors might occur due to:
- Insufficient permissions to make the request to the backend
- Incorrect fields for the API ID, AWS Region, and API stage
- Errors in the backend integration
- AWS Identity and Access Management (IAM) authentication errors
Follow these troubleshooting steps for your use case.
Confirm that the WebSocket API has the required permissions to make a request to the backend
API Gateway uses IAM roles, policies, tags, and AWS Lambda authorizers to control access to a WebSocket API. For more information, see Controlling and managing access to a WebSocket API in API Gateway.
Also, make sure that the WebSocket API integration request is configured correctly.
Confirm that the request is sent to the correct API ID, AWS Region, and API stage
In this example request URL, make sure that the following fields are correct:
- The WebSocket API ID "a1b2c3d4e5".
- The AWS Region "us-east-1".
- The API stage name "production" exists.
Check CloudWatch logs for errors
Follow the instructions to turn on Amazon CloudWatch logs for troubleshooting API Gateway WebSocket APIs. If a Lambda function is integrated for the backend, check the CloudWatch logs for errors. For more information, see Accessing CloudWatch logs for AWS Lambda.
Confirm that the API request is signed if the API method has IAM authentication turned on
To turn on IAM authentication for your API Gateway API, follow these steps:
- In the API Gateway console, choose the name of your API.
- In the Resources pane, choose a method (such as GET or POST) that you want to activate IAM authentication for.
- In the Method Execution pane, choose Method Request.
- Under Settings, for Authorization, choose the pencil icon (Edit). Choose AWS_IAM from the dropdown list, and then choose the check mark icon (Update).
- (Optional) Repeat steps 2-4 for each API method that you want to activate IAM authentication for.
- Deploy your WebSocket API for the changes to take effect.