Fleet Provisioning by Claim Fails: MQTT Subscribe Timeout on $aws/provisioning-templates Topics
I am trying to implement Fleet Provisioning by Claim for AWS IoT Core. I created a Fleet Provisioning Template of type FLEET_PROVISIONING. I created a Claim Certificate with the following policy attached: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["iot:Connect", "iot:Publish", "iot:Subscribe", "iot:Receive"], "Resource": "" }, { "Effect": "Allow", "Action": ["iot:Publish", "iot:Subscribe", "iot:Receive"], "Resource": [ "arn:aws:iot:us-east-1:<account-id>:topic/$aws/provisioning-templates/MyFleetProvisioningTemplate/", "arn:aws:iot:us-east-1:<account-id>:topicfilter/$aws/provisioning-templates/MyFleetProvisioningTemplate/*" ] } ] }
I use the AWSIoTPythonSDK to connect to IoT Core using the Claim Certificate. MQTT connect() succeeds. Publishing a fleet provisioning request to: $aws/provisioning-templates/MyFleetProvisioningTemplate/provision/json also succeeds (no error on publish).
- Connection is successful.
- Publish is successful.
When I try to subscribe to: $aws/provisioning-templates/MyFleetProvisioningTemplate/provision/accepted $aws/provisioning-templates/MyFleetProvisioningTemplate/provision/rejected
the subscribe operation times out.
I observe repeated disconnect / reconnect cycles in MQTT logs. After timeout, no accepted or rejected message is ever received. No new Thing or Certificate is created.
Here are the logs - C:\Development\repo\FleetProvisioningSimulator>python device_simulator3.py 2025-04-28 15:19:26,686 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Initializing MQTT layer... 2025-04-28 15:19:26,687 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Registering internal event callbacks to MQTT layer... 2025-04-28 15:19:26,687 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - MqttCore initialized 2025-04-28 15:19:26,688 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Client id: provisioning-client 2025-04-28 15:19:26,688 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Protocol version: MQTTv3.1.1 2025-04-28 15:19:26,688 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Authentication type: TLSv1.2 certificate based Mutual Auth. 2025-04-28 15:19:26,688 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring endpoint... 2025-04-28 15:19:26,689 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring certificates and ciphers... 2025-04-28 15:19:26,689 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queueing: max queue size: -1 2025-04-28 15:19:26,689 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queue draining interval: 0.500000 sec 2025-04-28 15:19:26,689 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring connect/disconnect time out: 10.000000 sec 2025-04-28 15:19:26,690 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring MQTT operation time out: 5.000000 sec Connecting to AWS IoT Core with Claim Certificate... 2025-04-28 15:19:26,690 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync connect... 2025-04-28 15:19:26,690 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing async connect... 2025-04-28 15:19:26,690 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Keep-alive: 600.000000 sec 2025-04-28 15:19:26,691 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event consuming thread started 2025-04-28 15:19:26,691 - AWSIoTPythonSDK.core.protocol.mqtt_core - DEBUG - Passing in general notification callbacks to internal client... 2025-04-28 15:19:26,691 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in fixed event callbacks: CONNACK, DISCONNECT, MESSAGE 2025-04-28 15:19:27,665 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Starting network I/O thread... 2025-04-28 15:19:27,972 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Produced [connack] event 2025-04-28 15:19:27,973 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Dispatching [connack] event 2025-04-28 15:19:27,973 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - No need for recovery 2025-04-28 15:19:27,974 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Invoking custom event callback... Connected! Subscribing to: $aws/provisioning-templates/MyFleetProvisioningTemplate/provision/accepted 2025-04-28 15:19:27,974 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync subscribe... 2025-04-28 15:19:27,975 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Adding a new subscription record: $aws/provisioning-templates/MyFleetProvisioningTemplate/provision/accepted qos: 1 2025-04-28 15:19:27,975 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in custom suback event callback... 2025-04-28 15:19:28,279 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Produced [disconnect] event 2025-04-28 15:19:28,279 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Dispatching [disconnect] event 2025-04-28 15:19:28,280 - AWSIoTPythonSDK.core.protocol.connection.cores - DEBUG - backOff: current backoff time is: 1 sec. 2025-04-28 15:19:28,280 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Invoking custom event callback... 2025-04-28 15:19:30,840 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Produced [connack] event 2025-04-28 15:19:30,840 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Dispatching [connack] event 2025-04-28 15:19:30,843 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Has recovery job 2025-04-28 15:19:30,846 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Start resubscribing 2025-04-28 15:19:30,846 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Invoking custom event callback... 2025-04-28 15:19:30,847 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in custom suback event callback... 2025-04-28 15:19:31,146 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Produced [disconnect] event 2025-04-28 15:19:31,147 - AWSIoTPythonSDK.core.protocol.connection.cores - DEBUG - backOff: current backoff time is: 2 sec. 2025-04-28 15:19:31,147 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Dispatching [disconnect] event 2025-04-28 15:19:31,149 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Invoking custom event callback... 2025-04-28 15:19:32,979 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Removing custom event callback... 2025-04-28 15:19:32,980 - AWSIoTPythonSDK.core.protocol.mqtt_core - ERROR - Subscribe timed out Exception occurred: Disconnecting... 2025-04-28 15:19:32,984 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync disconnect... 2025-04-28 15:19:32,985 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing async disconnect... 2025-04-28 15:19:32,987 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in custom disconnect event callback... 2025-04-28 15:19:42,999 - AWSIoTPythonSDK.core.protocol.mqtt_core - ERROR - Disconnect timed out Traceback (most recent call last): File "C:\Development\repo\FleetProvisioningSimulator\device_simulator3.py", line 83, in <module> claim_client.disconnect() ~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\jj\AppData\Roaming\Python\Python313\site-packages\AWSIoTPythonSDK\MQTTLib.py", line 580, in disconnect return self._mqtt_core.disconnect() ~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\jj\AppData\Roaming\Python\Python313\site-packages\AWSIoTPythonSDK\core\protocol\mqtt_core.py", line 246, in disconnect raise disconnectTimeoutException()
======CODE============= import json import time from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient import logging
Setup logging
logger = logging.getLogger("AWSIoTPythonSDK.core") logger.setLevel(logging.DEBUG) stream_handler = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') stream_handler.setFormatter(formatter) logger.addHandler(stream_handler)
Configuration
ENDPOINT = <myendpoint> # Example: "a1234567890wxyz-ats.iot.us-east-1.amazonaws.com" TEMPLATE_NAME = "MyFleetProvisioningTemplate"
CLAIM_CERT = "certs/claim-certificate.pem.crt" CLAIM_PRIVATE_KEY = "certs/claim-private.pem.key" ROOT_CA = "certs/AmazonRootCA1.pem"
THING_NAME = "Device_001" SERIAL_NUMBER = "SN-001" DEVICE_LOCATION = "Seattle"
MQTT Client Setup
claim_client = AWSIoTMQTTClient("provisioning-client") claim_client.configureEndpoint(ENDPOINT, 8883) claim_client.configureCredentials(CAFilePath=ROOT_CA, KeyPath=CLAIM_PRIVATE_KEY, CertificatePath=CLAIM_CERT) claim_client.configureOfflinePublishQueueing(-1) claim_client.configureDrainingFrequency(2) claim_client.configureConnectDisconnectTimeout(10) claim_client.configureMQTTOperationTimeout(5)
MQTT Topics
accepted_topic = f"$aws/provisioning-templates/{TEMPLATE_NAME}/provision/accepted" rejected_topic = f"$aws/provisioning-templates/{TEMPLATE_NAME}/provision/rejected" provisioning_topic = f"$aws/provisioning-templates/{TEMPLATE_NAME}/provision/json"
Message Callback
def on_message(client, userdata, message): print(f"\nReceived message on topic: {message.topic}") payload = message.payload.decode() print(f"Payload: {payload}")
Main Logic
try: print("Connecting to AWS IoT Core with Claim Certificate...") claim_client.connect() print("Connected!")
# Subscribe to accepted and rejected topics BEFORE publishing
print(f"Subscribing to: {accepted_topic}")
claim_client.subscribe(accepted_topic, 1, on_message)
print(f"Subscribing to: {rejected_topic}")
claim_client.subscribe(rejected_topic, 1, on_message)
# Small delay to allow subscription setup
time.sleep(2)
# Create the provisioning payload
provisioning_payload = {
"parameters": {
"ThingName": THING_NAME,
"SerialNumber": SERIAL_NUMBER,
"DeviceLocation": DEVICE_LOCATION
}
}
# Publish the provisioning request
print(f"Publishing provisioning request to {provisioning_topic}...")
claim_client.publish(provisioning_topic, json.dumps(provisioning_payload), 1)
# Wait to receive response
print("Waiting for Fleet Provisioning response (15 seconds)...")
time.sleep(15)
except Exception as e: print(f"Exception occurred: {e}")
finally: print("Disconnecting...") claim_client.disconnect() print("Disconnected.")
- Language
- English
asked 2 years ago176 views
- Newest
- Most votes
- Most comments
Hey,
Hope you're keeping well.
It looks like the subscribe failure is due to insufficient permissions in your claim certificate policy. For Fleet Provisioning by Claim, the policy must allow iot:Subscribe and iot:Receive on the topicfilter ARNs for both provision/accepted and provision/rejected, not just the root template path. Also, the Resource for iot:Connect should reference your IoT Core endpoint client ID with a wildcard, e.g. arn:aws:iot:us-east-1:<account-id>:client/*.
Thanks and regards,
Taz
answered a year ago
