amazon-cognitoamazon-iamaws-iotaws-iot-core

Connecting to AWS MQTT broker using Cognito Identity Pool temporary credentials


I'm attempting to establish a connection to the IoT Core broker using temporary credentials from cognito identity pools (access key/secret key/session token) in Python. Unfortunately, my current approach results in a timeout without clear error messages. I've experimented with different libraries like AWSIoTPythonSDK.MQTTLib, awscrt, and Paho (noticed Paho being used within AWSIoTPythonSDK), but none have been successful. To clarify, I'm looking to connect directly to the broker without involving any specific IoT things that I may have created (I have been able to connect to a thing using credentials but not the broker itself). I've come across suggestions that I might need to create an IoT Core policy and attach it to the Identity Pool role. I attempted this using the CLI (as there seems to be no option for it in the UI), but it hasn't yielded any positive results. If someone could guide me on the correct approach to connect to the IoT Core MQTT broker using my temporary credentials from Cognito, it would greatly help avoid further troubleshooting headaches as it may be the case that I misunderstand the use case completely .

Thank you.


Solution

  • You could try the V2 IoT Python SDK: https://pypi.org/project/awsiotsdk/

    There's a sample demonstrating how to connect to IoT Core using Cognito, see the corresponding readme and the sample itself.