0

I need to trigger the function on the basis of the topic, that if the user is subscribed to the topic or the messages being sent on different topics so that I can Identify the topic the message is sent to and also the message being sent over that topic. Messages are coming from the hardware devices into the broker over the MQTT topic. And I want to invoke lambda on the basis of the topic and the message payoad.

On the basis of this, I need to manage the further functionality in the database and backend.

Raman Saini
  • 365
  • 1
  • 11
  • If I understood this correctly, then you can create a new SQS queue which will trigger your lambda. You can push a message to this queue when you publish to your topic. This message will contain the data published to the topic (topic name and message). The SQS message will be received by your lambda and in the lamda you can do your further actions related to backend. – PR7 Dec 16 '21 at 10:04
  • But will it cause any latency? or is there any other way to trigger lambda over topics? – Raman Saini Dec 16 '21 at 11:22
  • You can directly trigger lambda from code as well, but make sure you handle the error cases well. With SQS you get features like dead letter queue and ability to retry message in case of error which makes error handling little bit easier. – PR7 Dec 16 '21 at 11:30
  • Can you please share any references? – Raman Saini Dec 16 '21 at 11:33
  • For invoking lambda from code you can use AWS SDK, here is the example for javascript but AWS SDK is available for other languages as well. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property – PR7 Dec 16 '21 at 11:54
  • Can the messages that come from the topic be sent to this SQS from amazon MQ directly? – Raman Saini Dec 17 '21 at 08:55
  • You can invoke the lambda directly from MQ as well, if this use case works for you. https://aws.amazon.com/blogs/compute/using-amazon-mq-as-an-event-source-for-aws-lambda/ – PR7 Dec 17 '21 at 14:01
  • Yes, but it works only for queues, not for topics. – Raman Saini Dec 18 '21 at 06:27
  • It should be possible for topics as well in my opinion, although i've never triggered lambda with a topic before. Maybe this post can help you https://stackoverflow.com/questions/48044761/possible-to-subscribe-to-aws-iot-topic-in-lambda – PR7 Dec 18 '21 at 09:36

0 Answers0