lambda post messages in mqtt iot core
Hey,
Quite new here and im looking for an solution. Currently i've created a python script and uploaded to aws lambda function. The code gathers data from an external api and stores it into a dynamodb database. This part works fine. For part 2 i would like to post this data into an MQTT broker like IoT core where my external IoT device can subscribe to and read incomming messages. I couldn't find any solution/documentation about this topic so i hope someone can explain me or help me out.
- Language
- English
asked 2 years ago932 views
- Newest
- Most votes
- Most comments
Hi! There are a couple approaches you can take. If the Lambda just needs to publish a message, you can POST via HTTPS. Grant the Lambda function's IAM role the iot:Publish action, and use HTTP on port 443 as noted here using Signature v4.
If the Lambda also requires to subscribe to an MQTT topic, then an X.509 certificate for mTLS or an MQTT over WebSocket connection can be used.
No changes needed on the devices subscribing to the topic.
- rePost-User-14525542 years ago
It should only post message to the broker which the exenternal IoT devices could subscribe on. So i need to add this in my code ? or create a new thing in IoT Core?
- Gavin_A2 years ago
No need to create a Thing, certificate, or IoT policy in IoT Core in that case. The only IAM resource needed is
iot:Publish. Here is an example of doing this in boto3 (Python) and Node.js. And Rust example too. If you could accept the answer if this does address your question, much appreciated.
The simplest approach is to then trigger another lambda function in response to dynamo streams:
https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#
You could also into eventbridge pipes. Your source will be the stream and your target could any of those: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-event-target.html
Relevant content
asked 4 years ago
asked 4 years ago
- Accepted Answer
asked 3 years ago
