Save data to DynamoDB
For details about how to deply DynamoDB and AWS CLI locally, please see Deploying DynamoDB Locally (opens new window)
Initiate the DynamoDB table:
1). Create table definition file “mqtt_msg.json” for DynamoDB:
2). Create the DynamoDB table:
Create a rule:
Go to , select the “rule” tab on the menu to the left.
Select “message.publish”, then type in the following SQL:
Bind an action:
Click on the “+ Add” button under “Action Handler”, and then select “Data to DynamoDB” in the pop-up dialog window.
Fill in the parameters required by the action:
Four parameters is required by action “Data to DynamoDB”:
1). DynamoDB Table. Here set it to “mqtt_msg”.
2). Hash Key. Here set it to “msgid”.
3). DynamoDB Range Key. Leave it empty as we didn’t define a range key in the dynamodb definition file.
4). Bind a resource to the action. Since the dropdown list “Resource” is empty for now, we create a new resource by clicking on the “New Resource” to the top right, and then select “DynamoDB”:
Configure the resource:
And then click on the “Create” button.
Back to the “Actions” dialog, and then click on the “Confirm” button.
Back to the creating rule page, then click on “Create” button. The rule we created will be show in the rule list:
We have finished, testing the rule by sending an MQTT message to emqx:
Then inspect the DynamoDB table, verify a new record has been inserted: