- Newest
- Most votes
- Most comments
To access retained messages in AWS IoT Core after connecting, you need to understand a few key concepts about how AWS IoT Core handles retained messages.
When you publish MQTT messages with the RETAIN flag set, AWS IoT Core stores these messages, and they appear in the retained messages menu of the Amazon console as you've observed. However, unlike some other MQTT brokers, AWS IoT Core doesn't automatically send retained messages to clients upon connection and subscription.
To retrieve retained messages in AWS IoT Core, you have two options:
-
Use persistent sessions: Set the
clean_sessionparameter toFalsewhen connecting your MQTT client. With a persistent session, the message broker stores messages while the device is disconnected and delivers them when the device reconnects. This approach works for messages sent while you were disconnected but had an active subscription. -
Explicitly retrieve retained messages: Since AWS IoT Core doesn't automatically send retained messages upon connection, you need to use the AWS IoT API to retrieve them:
- Use
ListRetainedMessagesto get a list of topic names for retained messages - Use
GetRetainedMessagewith the specific topic name to retrieve the message payload
Note that using these API calls requires proper permissions in your AWS IoT policy. You'll need to ensure your policy includes permissions to access the ListRetainedMessages and GetRetainedMessage actions.
The behavior you're experiencing is expected with AWS IoT Core, as it handles retained messages differently from some other MQTT brokers that might automatically send retained messages upon subscription.
Sources
Retained message policy examples - AWS IoT Core
ListRetainedMessages - AWS IoT
list_retained_messages - Boto3 1.37.31 documentation
Tutorial: Connecting a device to AWS IoT Core by using the AWS IoT Device SDK - AWS IoT Core
answered a year ago
Thank you for your reply. How can I use the Rest HTTP API to retrieve retained messages?
There is hardly any information in the documentation, and it does not indicate how I should authenticate myself.
There is only a final endpoint, but no example of the parameters I need to authenticate myself.
answered a year ago
Relevant content
asked a year ago
asked 2 years ago
asked 2 years ago
