AWS IoT & Lambda: Triggering function using rule A works but not using rule B

Viewed 104

Four components are related to this question:

  1. The "IoT client": A program that runs in IoT devices, connects to AWS and publishes/subscribes to topics,
  2. a Lambda function with two different versions: 1 and 2,
  3. an AWS IoT rule (#1) that triggers version 1 of the Lambda function, and
  4. an AWS IoT rule (#2) that triggers version 2 of the Lambda function.

Version 2 of the Lambda function introduced breaking changes requiring a new version of the IoT client.

IoT rule #1 uses $aws/rules/DoSomething/${device_id} IoT rule #2 uses $aws/rules/do_something/${device_id}

Version 1 of the IoT client uses rule #1 and version 2 of the IoT client uses rule #2. At this point in the IoT client's code, nothing else has changed except changing DoSomething to do_something.

Using the AWS IoT console, I duplicated rule #2, renamed it to do_something instead of DoSomething and changed the target to version 2 of the Lambda function instead of version 1.

I have checked the configuration->permissions settings of both versions, and they are identical (allowing writing to the Lambda function's CloudWatch Logs, not version-specific). Both versions are triggered using the same IAM role.

Lambda function v1 has IoT rule #1 as a trigger. Lambda function v1 is also an action of IoT rule #1. Lambda function v2 has IoT rule #2 as a trigger. Lambda function v2 is also an action of IoT rule #2.

Yet, when the IoT client uses IoT rule #2, the function is never triggered. If I change the rule to IoT rule #1, it triggers the function.

The only thing I need to change to make it trigger some function is do_something -> DoSometing, but I don't want DoSomething, I want do_something.

Comparing the two rules in the console, nothing is changed (as far as I can see) except DoSomething -> do_something and the Lambda function version under Actions. The SQL statements are the same.

The two function versions are also identical (as far as I can see) except their code, the version and which rule is hooked up as a trigger.

What did I miss?

1 Answers

Check the policy attached to the certificate, which is in turn attached to the thing(device) which is used to publish.

There is a chance that the topic is limited to a certain format like starting with or containing some string.AWS IoT Core action resources

For example, the policy may dictate to have all topics start like $aws/rules/DoSomething/

You can make use of the MQTT Test client in order to check whether the topic used for publishing is proper, It's available under IOT core itself.AWS IoT MQTT client

Related