How can I troubleshoot 410 GoneException errors with Amazon API Gateway WebSocket APIs?

2 minute read
0

I get a "410 GoneException" error when trying to post a message to my Amazon API Gateway WebSocket API similar to the following: ... "errorMessage": "GoneException: 410" ... How do I troubleshoot this?

Short description

You might receive the "410 GoneException" error if:

  • A message was posted to the WebSocket API before the connection was established.
  • The connection has been terminated, or the connection doesn't exist anymore.
  • The client disconnected and then tried to reconnect using the same connectionId.

Note: For WebSocket APIs, the connectionId is required to send a callback response from the backend.

Resolution

To troubleshoot WebSocket API errors, turn on Amazon CloudWatch Logs.

Note: For Log level, choose INFO to generate execution logs for all requests.

Execution logs contain information that you can use to identify and troubleshoot most API errors. For example:

For more information about each type of logging, see CloudWatch log formats for API Gateway.

Before posting messages to WebSocket APIs, make sure that your connection is established by calling the getConnection operation using the AWS SDK ApiGatewayManagementApi.

Avoid making the postToConnection request from the Lambda function integrated with your $connect route. For example, if you want to post a message after the client connection is established, do the following:

  1. Create a child Lambda function that's asynchronously invoked by the parent function.
  2. On initiation of a new connection, the $connect route is invoked and the parent function invokes the child function passing the connectionId.
  3. The Lambda child function receives the connectionId and calls the getConnection operation to verify that the connection is valid. Then, the message is sent using the postToConnection method.

Related information

About WebSocket APIs in API Gateway

How can I pass a connectionId or custom token to VPC Link integration as a header for Amazon API Gateway WebSocket APIs?

AWS OFFICIAL
AWS OFFICIALUpdated a year ago
2 Comments

We have followed all of this guidance, yet occasionally we get a GoneException 401 two minutes after WSS connection and 20 seconds before a following message sent to postToConnection does successfully deliver. There are no disconnections in the meantime shown either in the browser console nor in the OnDisconnectFunction CW log.

It would be helpful if the GoneException had a message property providing an explanation.

MODDZP
replied 10 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed

profile pictureAWS
MODERATOR
replied 10 months ago