How to catch exception Websocket Handshake Error while using Cognito Identity
See original GitHub issueI’m trying to connect to AWS IoT by using Cognito Identity (Authenticated Identity), claim temporary IAM credentials then connect, all operation work as normal until network down.
For example, network down for 4 hour and then has internet connection as normal. The problem is temporary credentials cannot refresh while network down (i’m refreshing it inside disconnect callback) and while SDK trying to reconnect when internet connection back, at that time, the IAM credentials has been out dated and it will cause Websocket Handshake Error exception and stuck forever.
So I need help to caught exception when above problem happens in order to refresh IAM and reconnect again.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Managing error responses - Amazon Cognito
To sign a user in with ADMIN_USER_PASSWORD_AUTH and USER_PASSWORD_AUTH , include the user name and password in an AdminInitiateAuth or InitiateAuth API request....
Read more >WebSocket connection failed: Error during ... - Stack Overflow
Problem solved! I just figured out how to solve the issue, but I would still like to know if this is normal behavior...
Read more >Stomp WebSocket Connection with Server side authorization ...
Client sends request for authorization to Cognito by providing user id/password and gets identity token in return (along with refresh token and ...
Read more >WebSocket was closed: An exception has occurred while ...
You may need to verify the WebSocket connection on ADS works properly. You can use the rmdstestclient or testclient tool available in the...
Read more >amazon-cognito-identity-js - npm
Start using amazon-cognito-identity-js in your project by running `npm ... Download the amazon-cognito-identity-js package from npm and get ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, what I’m suggesting is when you receive a disconnect, to start fetching credentials and retry until it succeeds, then update the credentials in the MQTT connection so its next attempt will succeed.
For what it’s worth, this problem is not present in our upcoming v2 version of this SDK, because all of the events are hookable.
Hi guys, I am curious about the “on_disconnect” callback func and the renew credentials for websocket handshake issue. May anyone of you can provide the sample code of how you fix this issue? Big thanks,