review AWS IoT Rule

Please open AWS IoT Rules console by clicking on this link or navigating to AWS IoT, Act, Rules.

1. Find the IoT Rule MyWorkshopLoRaWANRuleWithDecoder_…

Please put the IoT Rule name prefix MyWorkshopLoRaWANRuleWithDecoder_ into the search field and click on the search symbol. The rule named MyWorkshopLoRaWANRuleWithDecoder_<Decoder name> should appear: AWS Management Console

2. Review the AWS IoT Rule

Please always select SQL Version 2016-03-23 or above for your AWS IoT Rules processing LoRaWAN payloads!

Please click on the IoT Rule name. Scroll down to “Rule query statement section” and click on “Edit”: AWS Management Console

Now you can review the IoT Rule query statement and IoT Rule action: AWS Management Console

1.IoT Rule query statement
You can see that the created AWS IoT Rule will invoke the AWS Lambda function for binary decoding which we reviewed in a previous step. The IoT SQL query specifies the attributes of the payload that will be provided as parameters to the AWS Lambda function:

  • PayloadData
  • WirelessDeviceId
  • Metadata

2. The republish action will publish the transformed payload to the topic dt/workshop/transformed of AWS IoT Core MQTT broke.
3. The error action will be invoked if the invocation of the rule action fails, e.g. due to a lack of permissions to publish to a specified MQTT topic or to invoke AWS Lambda function.

By adding further actions to the AWS IoT Rule you can process the decoded payloads with further AWS services, for example store in Amazon S3 or Amazon Timestream for analytics, forward to AWS Sitewise for dashboarding, and many more.

Notice on common pitfalls::

  1. If AWS Lambda function specified in the IoT SQL statement has been successfully invoked (in terms of the API call returning 200), but the function fails during the execution, the error action will not be called. Please refer to error handling section in AWS Lambda developer guide for a description of how you can handle errors during AWS Lambda execution.
  2. In the AWS IoT rule action expressions, when accessing attributes via ${variable_name} construct, you can only access the attributes of the original message, but not the attributes of the calculations that you have defined in IoT Rule SQL statement. For example, if you want to define a key to a S3 Action, you can access the ${WirelessDeviceId} but not ${transformed_payload.battery_status}. To achieve the latter, you can republish the message to another IoT Rule.
  3. Please note that for AWS IoT Rules that are assigned to AWS IoT Core for LoRaWAN Destinations, the FROM clauses are ignored if the rule is invoked by AWS IoT Core for LoRaWAN. For example, a statement SELECT * FROM 'a/b' has the same effect as SELECT * when the rule is invoked via the AWS IoT Core for LoRaWAN Destination.