Menu
AWS IoT
Developer Guide

DynamoDB Action

The dynamoDB action allows you to write all or part of an MQTT message to a DynamoDB table. When creating a DynamoDB rule, you must specify the following information:

hashKeyType

The data type of the hash key (also called the partition key). Valid values are: "STRING" or "NUMBER".

hashKeyField

The name of the hash key (also called the partition key).

hashKeyValue

The value of the hash key.

rangeKeyType

Optional. The data type of the range key (also called the sort key). Valid values are: "STRING" or "NUMBER".

rangeKeyField

Optional. The name of the range key (also called the sort key).

rangeKeyValue

Optional. The value of the range key.

operation

Optional. The type of operation to be performed. This follows the substitution template, so it can be ${operation}, but the substitution must result in one of the following: INSERT, UPDATE, or DELETE.

payloadField

Optional. The name of the field where the payload is written. If this value is omitted, the payload is written to the payload field.

table

The name of the DynamoDB table.

roleARN

The IAM role that allows access to the DynamoDB table. At a minimum, the role must allow the dynamoDB:PutItem IAM action.

The data written to the DynamoDB table is the result from the SQL statement of the rule. The hashKeyValue and rangeKeyValue fields are usually composed of expressions (for example, "${topic()}" or "${timestamp()}").

Note

Non-JSON data is written to DynamoDB as binary data. The DynamoDB console displays the data as Base64-encoded text.

Ensure the role associated with the rule has a policy granting the dynamodb:PutItem permission.

The following JSON example shows how to define a dynamoDB action in an AWS IoT rule:

{ "rule": { "ruleDisabled": false, "sql": "SELECT * AS message FROM 'some/topic'", "description": "A test Dynamo DB rule", "actions": [{ "dynamoDB": { "hashKeyField": "key", "roleArn": "arn:aws:iam::123456789012:role/aws_iot_dynamoDB", "tableName": "my_ddb_table", "hashKeyValue": "${topic()}", "rangeKeyValue": "${timestamp()}", "rangeKeyField": "timestamp" } }] } }

For more information, see the Amazon DynamoDB Getting Started Guide.