lambda post messages in mqtt iot core

0

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.

asked a month ago174 views
2 Answers
2
Accepted Answer

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.

AWS
Gavin_A
answered a month 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?

  • 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.

0

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

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions