AWS IoT Python SDK
raw JSON → 1.6.0 verified Fri May 01 auth: no python maintenance
The AWS IoT Python SDK (awsiotpythonsdk) allows Python developers to connect devices to AWS IoT via MQTT, HTTP, and WebSocket. Current stable version is 1.6.0, with no official release cadence. It is the predecessor to the newer awsiotsdk (v2+), which is now recommended for new projects.
pip install awsiotpythonsdk Common errors
error ModuleNotFoundError: No module named 'AWSIoTPythonSDK' ↓
cause The installed package name (awsiotpythonsdk) is all lowercase but the import uses CamelCase.
fix
Run: pip install awsiotpythonsdk, then import with: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
error SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ↓
cause The root CA path is incorrect or the certificate is missing in the credential bundle.
fix
Download the correct Amazon Root CA file from https://www.amazontrust.com/repository/ and pass the path to configureCredentials(). Ensure the file exists and is readable.
error ClientError: Connection refused or timeout ↓
cause The endpoint or port is wrong, or the device certificate is not registered/active in AWS IoT.
fix
Double-check the endpoint address (should be something like xxxxxx-ats.iot.<region>.amazonaws.com) and port (8883 for X.509). Also ensure the certificate is attached to a policy that allows connect.
Warnings
gotcha Import path uses 'AWSIoTPythonSDK' with mixed case, not 'awsiotpythonsdk'. The PyPI package name is all lowercase, but the Python module name is CamelCase. ↓
fix Use: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
deprecated awsiotpythonsdk v1 is in maintenance mode. AWS IoT Device SDK v2 (awsiotsdk) is the recommended replacement with async support and newer features. ↓
fix For new projects, use `awsiotsdk` instead of `awsiotpythonsdk`. Migration guide available in the v2 repo.
breaking The AWSIoTMQTTClient's connect() will block indefinitely if the broker is unreachable. No built-in timeout by default. ↓
fix Use a separate thread or set a socket timeout via configureConnectDisconnectTimeout(). Alternative: switch to awsiotsdk v2 which has proper async connect.
Imports
- AWSIoTMQTTClient wrong
import AWSIoTMQTTClientcorrectfrom AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient - AWSIoTMQTTShadowClient
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient
Quickstart
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
import logging
logging.basicConfig(level=logging.INFO)
# Use environment variables or placeholders
endpoint = os.environ.get('AWS_IOT_ENDPOINT', 'your-iot-endpoint.amazonaws.com')
client_id = os.environ.get('AWS_IOT_CLIENT_ID', 'myClientId')
root_ca = os.environ.get('AWS_IOT_ROOT_CA', '/path/to/AmazonRootCA1.pem')
private_key = os.environ.get('AWS_IOT_PRIVATE_KEY', '/path/to/private.pem.key')
cert_file = os.environ.get('AWS_IOT_CERT_FILE', '/path/to/certificate.pem.crt')
myClient = AWSIoTMQTTClient(client_id)
myClient.configureEndpoint(endpoint, 8883)
myClient.configureCredentials(root_ca, private_key, cert_file)
myClient.connect()
print('Connected to AWS IoT')
myClient.disconnect()