'Web-socket Handshake Error AWS IOT

I am getting this WebSocket Handshake Error when I try to connect to AWS IOT using aws-iot-python-sdk. I am using WebSocket + MQTT version to publish and receive data. Very weird thing is that it was working fine just few hours ago, not a single line of change in code, just starting throwing error, I am confused what has happened? Is it AWS IOT itself or something is happening on my side !!!

The code I am using to connect to AWS IOT.

from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
from config import IOT_ENDPOINT, IOT_CREDENTIAL_PATH

def connect(mqttClientId):
  try:
    myMQTTClient = AWSIoTMQTTClient(mqttClientId, useWebsocket=True)
    myMQTTClient.configureEndpoint(IOT_ENDPOINT, 443)
    myMQTTClient.configureCredentials(IOT_CREDENTIAL_PATH)

    myMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
    # Infinite offline Publish queueing
    myMQTTClient.configureOfflinePublishQueueing(-1)
    myMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
    myMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
    myMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec

    myMQTTClient.connect()
    return myMQTTClient
  except Exception as error:
    print(error)
    print "No Internet Connection... Can't connect AWS IOT"

Thank You.



Solution 1:[1]

Looks like your credentials issued by STS has been expired. To solve this you will need to refresh each time the connection goes offline:

creds = provider.load()
awsiot.configureIAMCredentials(...)

More information you can take a look on this issue Disconnect followed by Websocket Handshake Error #215

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1