Search code examples
amazon-web-servicesaws-iotaws-iot-core

AWS IoT Publish a retained message using SDK


I'm looking for a way to publish a message to an IoT topic with a "retained flag" set to true. I have been unable to find a way to do so using the python SDK.

From what I can tell the publish method only takes 3 arguments as listed below:

thisAWSIoTMQTTClient.publish("Topic", "Payload", "QoS")

When playing around in the IoT console it is very straight forward and according to AWS documentation it should be possible:

You can use the AWS IoT Device SDKs or your own MQTT 3.1.1 compliant client to publish a retained message

But can anyone show me how?


Solution

  • Yes it is possible but your aws iot python v2 sdk needs at least the awscrt python 0.16.0 version. Make sure you update have the latest aws iot python v2 sdk configured. See awscrt version mentioned in aws iot python v2 sdk and the publish method with the retain flag.