Menu
AWS IoT
Developer Guide

AWS IoT SQL Reference

In AWS IoT, rules are defined using an SQL-like syntax. SQL statements are composed of three types of clauses:

SELECT

Required. Extracts information from the incoming payload and performs transformations.

FROM

Required. The MQTT topic filter from which the rule will receive messages.

WHERE

Optional. Adds conditional logic that determines if a rule is evaluated and its actions are executed.

An example SQL statement looks like this:

Copy
SELECT color AS rgb FROM 'a/b' WHERE temperature > 50

An example MQTT message (also called an incoming payload) looks like this:

Copy
{ "color":"red", "temperature":100 }

If this message is published on the 'a/b' topic, the rule is triggered and the SQL statement is evaluated. The SQL statement extracts the value of the rgb property if the "temperature" property is greater than 50. The WHERE clause specifies the condition temperature > 50. The AS keyword renames the "color" property to "rgb". The result (also called an outgoing payload) looks like this:

Copy
{ "rgb":"red" }

This data is then forwarded to the rule's action, which sends the data for more processing. For more information about rule actions, see AWS IoT Rule Actions.