On the Create a rule page, enter a name and description for your
rule.

Note

We do not recommend using personally identifiable information in your rule names or
descriptions.

Under Rule query statement, choose the latest version from the
Using SQL version list. For Rule query
statement, enter:

SELECT * FROM 'my/greenhouse'

("SELECT *" specifies that you want to send the entire MQTT message that
triggered the rule. "FROM 'my/greenhouse'" tells the rules engine to trigger
this rule when an MQTT message is received whose topic matches this topic filter.

In Set one or more actions, choose Add action.

On the Select an action page, choose
Insert a message into a DynamoDB table, and then choose Configure action.

On the Configure action page, choose Create a new resource.

On the Amazon DynamoDB page, choose Create table.

On the Create DynamoDB table page, enter a name in
Table name. In Partition key, enter
Intersection. Select Add sort key, and then
enter TrafficLight in the Sort key field.
Choose String for both the partition and sort keys, and then choose
Create. It takes a few seconds to create your DynamoDB table. Close
the browser tab where the Amazon DynamoDB console is open. If you don't close the
tab, your
DynamoDB table is not displayed in the Table name list on the
Configure action page of the AWS IoT console.

On the Configure action page, choose your new table from the Table name
list. In Partition key value, enter ${row}. This instructs the rule to
take the value of the row attribute from the MQTT message and write it into the Row
column in the DynamoDB table. In Sort key value, enter ${index}. This writes
the value of the index attribute into the indexInRow column. Leave
Write message data to this column blank. By default, the entire message is written to a column in the table named Payload.
Choose Create a new role.

Under Choose or create a role to grant AWS IoT access to perform this action, choose Create Role.

In Create a new role, enter a unique name in
Name, and then choose Create role.

Choose Add action.

Choose Create rule to create your rule.

Testing an Amazon DynamoDB Rule

To test the rule, open the AWS IoT console and from the navigation pane, choose
Test.

Choose Publish to a topic. In the
Publish section, enter my/greenhouse as
the topic. In the message area, enter the following JSON:

{
"row" : "0",
"index : "0",
"moisture" : "75"
}

Return to the DynamoDB console and choose Tables.

Select the GreenhouseTable and then choose the
Items tab. Your data is displayed on the
Items tab.

Javascript is disabled or is unavailable in your browser.

To use the AWS Documentation, Javascript must be enabled. Please refer to your browser's
Help pages for instructions.