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.

已提問 1 個月前檢視次數 182 次
2 個答案
2
已接受的答案

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
已回答 1 個月前
  • 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
專家
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南