The AWS Lambda program sometimes fails to trigger, while other times it works correctly.

0

Hello, I have developed an AWS Lambda program to handle MQTT messages for AWS IoT. The program has been completed and is able to process messages. However, I have encountered an issue when using it: some MQTT messages fail to trigger the Lambda program. How can I troubleshoot this issue?

Details:

  1. During testing, MQTT messages are sent one by one without concurrent sending. The time interval between MQTT messages is more than 1 second.
  2. During testing, the app subscribes to MQTT messages and receives them. This confirms that the AWS server has successfully received and processed the MQTT messages. However, the Lambda program is not triggered.
  3. The Lambda program sometimes fails to trigger, while other times it works correctly. The issue occurs frequently, with approximately one-third of the operations experiencing problems.

How can I identify and resolve this issue?

大家好,我开发了一个 AWS Lambda 程序用来处理 AWS IoT 的 MQTT 消息。程序已经开发完了,并且能处理消息。但在使用时发现一个问题:有部分 MQTT 消息无法触发 Lambda 程序。请问这个问题应该如何排查?

说明:

  1. 测试时 MQTT 消息都是一条一条发送的,没有同时并发多条消息。并且 MQTT 消息之间的时间间隔都超过了 1 秒。
  2. 测试时 APP 有订阅 MQTT 消息,并且收到了 MQTT 消息,因此可以确认 AWS 服务器已经正确接收并处理了 MQTT 消息,但 Lambda 程序并没有被触发。
  3. Lambda 程序有时候不会被触发,有时候又能正常工作。问题出现的频率比较高,大概有三分之一的概率会出问题。

这个问题应该如何定位和解决?

asked 6 months ago197 views
1 Answer
0
Accepted Answer

Hi. Your AWS IoT Core rule may be suffering an error. Two ways to check for errors:

  1. Define an error action for the rule: https://docs.aws.amazon.com/iot/latest/developerguide/rule-error-handling.html. The easiest error action to use is to republish to another topic, so then you can observe the error in the MQTT test client.
  2. Enable AWS IoT logging to CloudWatch, and look for logs of rule action errors: https://docs.aws.amazon.com/iot/latest/developerguide/cwl-format.html#rule-engine-logs

If there's no error, then it may be that your rule is not matching even though you think it is. Again, you can look in the CloudWatch logs to see if you get a RuleMatch and RuleExecution event for the messages not processed by Lambda.

Since the rule calls Lambda asynchronously, it's also possible for the rule to succeed, but you get a problem before your Lambda code runs. Guidance here: https://dev.to/iotbuilders/how-to-ensure-resilience-for-your-aws-iot-rules-engine-to-aws-lambda-integration-1aoi

profile pictureAWS
EXPERT
Greg_B
answered 6 months 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