0
votes

I set up my Lambda function according to the AWS guides by setting a trigger in the setup stage. (the guide except that the guide is using IoT button and I'm using a rule)

It sets up the trigger rule in the AWS IoT console for me. The thing is setup with a certificate and an "iot:*" policy which gives it full IoT access.

The thing is continuously sending messages to the cloud under a certain topic. The messages can be received if I subscribe to it in the AWS IoT Test console.

My lambda function gets triggered if I publish something under that topic from the AWS IoT Test console.

But the function doesn't trigger from the continuous messages sent by the thing. It only triggers from the IoT Test console.

I didn't add any other policy under certificates for the thing in relation to this trigger. Do I have to do so? What should it be?

I tried changing my topic SQL to SELECT * FROM '*'

2

2 Answers

2
votes

Try to change your SQL to SELECT * FROM '#'. With # you get every published topic. When you use *, then you don't get topics e.g. sample/newTopic.

With this SQL statement the Lambdas Function gets invoked for every incoming message. When the AWS IoT Console shows the message and your Lambda Function doesn't do anything, try to look if Lambda did a log in CloudWatch.

0
votes

If your AWS IoT Thing can't trigger AWS Lambda function, you may have a JSON mapping issue and also to improve your SQL query. In my case, I used the following code to provide Lambda a clean input:

SELECT message.reported.* from "#"

With JSON mapping:

{
  "desired": {
    "light": "green",
    "Temperature": "55",
    "timestamp": 1526323886
  },
  "reported": {
    "light": "blue",
    "Temperature": "55",
    "timestamp": 1526323886
  },
  "delta": {
    "light": "green"
  }
}

Then you analyze CloudWatch logs:

CloudWatch

Then, check your AWS IoT Console for shadow updates (green below - "Atualizações de sombra") and also Publications (orange)

AWS IoT Console

So, your solution will look like this:

AWS IoT Solution

For full details of an end-to-end implementation of AWS IoT using Lambda, please access:

IoT Project - CPU Temperature from Ubuntu to AWS IoT