Table Of Contents

Feedback

User Guide

First time using the AWS CLI? See the User Guide for help getting started.

[ aws . iot ]

create-topic-rule

Description

Creates a rule. Creating rules is an administrator-level action. Any user who has permission to create rules will be able to access data processed by the rule.

See also: AWS API Documentation

See 'aws help' for descriptions of global parameters.

Synopsis

  create-topic-rule
--rule-name <value>
--topic-rule-payload <value>
[--tags <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Options

--rule-name (string)

The name of the rule.

--topic-rule-payload (structure)

The rule payload.

JSON Syntax:

{
  "sql": "string",
  "description": "string",
  "actions": [
    {
      "dynamoDB": {
        "tableName": "string",
        "roleArn": "string",
        "operation": "string",
        "hashKeyField": "string",
        "hashKeyValue": "string",
        "hashKeyType": "STRING"|"NUMBER",
        "rangeKeyField": "string",
        "rangeKeyValue": "string",
        "rangeKeyType": "STRING"|"NUMBER",
        "payloadField": "string"
      },
      "dynamoDBv2": {
        "roleArn": "string",
        "putItem": {
          "tableName": "string"
        }
      },
      "lambda": {
        "functionArn": "string"
      },
      "sns": {
        "targetArn": "string",
        "roleArn": "string",
        "messageFormat": "RAW"|"JSON"
      },
      "sqs": {
        "roleArn": "string",
        "queueUrl": "string",
        "useBase64": true|false
      },
      "kinesis": {
        "roleArn": "string",
        "streamName": "string",
        "partitionKey": "string"
      },
      "republish": {
        "roleArn": "string",
        "topic": "string",
        "qos": integer
      },
      "s3": {
        "roleArn": "string",
        "bucketName": "string",
        "key": "string",
        "cannedAcl": "private"|"public-read"|"public-read-write"|"aws-exec-read"|"authenticated-read"|"bucket-owner-read"|"bucket-owner-full-control"|"log-delivery-write"
      },
      "firehose": {
        "roleArn": "string",
        "deliveryStreamName": "string",
        "separator": "string"
      },
      "cloudwatchMetric": {
        "roleArn": "string",
        "metricNamespace": "string",
        "metricName": "string",
        "metricValue": "string",
        "metricUnit": "string",
        "metricTimestamp": "string"
      },
      "cloudwatchAlarm": {
        "roleArn": "string",
        "alarmName": "string",
        "stateReason": "string",
        "stateValue": "string"
      },
      "elasticsearch": {
        "roleArn": "string",
        "endpoint": "string",
        "index": "string",
        "type": "string",
        "id": "string"
      },
      "salesforce": {
        "token": "string",
        "url": "string"
      },
      "iotAnalytics": {
        "channelArn": "string",
        "channelName": "string",
        "roleArn": "string"
      },
      "iotEvents": {
        "inputName": "string",
        "messageId": "string",
        "roleArn": "string"
      },
      "iotSiteWise": {
        "putAssetPropertyValueEntries": [
          {
            "entryId": "string",
            "assetId": "string",
            "propertyId": "string",
            "propertyAlias": "string",
            "propertyValues": [
              {
                "value": {
                  "stringValue": "string",
                  "integerValue": "string",
                  "doubleValue": "string",
                  "booleanValue": "string"
                },
                "timestamp": {
                  "timeInSeconds": "string",
                  "offsetInNanos": "string"
                },
                "quality": "string"
              }
              ...
            ]
          }
          ...
        ],
        "roleArn": "string"
      },
      "stepFunctions": {
        "executionNamePrefix": "string",
        "stateMachineName": "string",
        "roleArn": "string"
      },
      "http": {
        "url": "string",
        "confirmationUrl": "string",
        "headers": [
          {
            "key": "string",
            "value": "string"
          }
          ...
        ],
        "auth": {
          "sigv4": {
            "signingRegion": "string",
            "serviceName": "string",
            "roleArn": "string"
          }
        }
      }
    }
    ...
  ],
  "ruleDisabled": true|false,
  "awsIotSqlVersion": "string",
  "errorAction": {
    "dynamoDB": {
      "tableName": "string",
      "roleArn": "string",
      "operation": "string",
      "hashKeyField": "string",
      "hashKeyValue": "string",
      "hashKeyType": "STRING"|"NUMBER",
      "rangeKeyField": "string",
      "rangeKeyValue": "string",
      "rangeKeyType": "STRING"|"NUMBER",
      "payloadField": "string"
    },
    "dynamoDBv2": {
      "roleArn": "string",
      "putItem": {
        "tableName": "string"
      }
    },
    "lambda": {
      "functionArn": "string"
    },
    "sns": {
      "targetArn": "string",
      "roleArn": "string",
      "messageFormat": "RAW"|"JSON"
    },
    "sqs": {
      "roleArn": "string",
      "queueUrl": "string",
      "useBase64": true|false
    },
    "kinesis": {
      "roleArn": "string",
      "streamName": "string",
      "partitionKey": "string"
    },
    "republish": {
      "roleArn": "string",
      "topic": "string",
      "qos": integer
    },
    "s3": {
      "roleArn": "string",
      "bucketName": "string",
      "key": "string",
      "cannedAcl": "private"|"public-read"|"public-read-write"|"aws-exec-read"|"authenticated-read"|"bucket-owner-read"|"bucket-owner-full-control"|"log-delivery-write"
    },
    "firehose": {
      "roleArn": "string",
      "deliveryStreamName": "string",
      "separator": "string"
    },
    "cloudwatchMetric": {
      "roleArn": "string",
      "metricNamespace": "string",
      "metricName": "string",
      "metricValue": "string",
      "metricUnit": "string",
      "metricTimestamp": "string"
    },
    "cloudwatchAlarm": {
      "roleArn": "string",
      "alarmName": "string",
      "stateReason": "string",
      "stateValue": "string"
    },
    "elasticsearch": {
      "roleArn": "string",
      "endpoint": "string",
      "index": "string",
      "type": "string",
      "id": "string"
    },
    "salesforce": {
      "token": "string",
      "url": "string"
    },
    "iotAnalytics": {
      "channelArn": "string",
      "channelName": "string",
      "roleArn": "string"
    },
    "iotEvents": {
      "inputName": "string",
      "messageId": "string",
      "roleArn": "string"
    },
    "iotSiteWise": {
      "putAssetPropertyValueEntries": [
        {
          "entryId": "string",
          "assetId": "string",
          "propertyId": "string",
          "propertyAlias": "string",
          "propertyValues": [
            {
              "value": {
                "stringValue": "string",
                "integerValue": "string",
                "doubleValue": "string",
                "booleanValue": "string"
              },
              "timestamp": {
                "timeInSeconds": "string",
                "offsetInNanos": "string"
              },
              "quality": "string"
            }
            ...
          ]
        }
        ...
      ],
      "roleArn": "string"
    },
    "stepFunctions": {
      "executionNamePrefix": "string",
      "stateMachineName": "string",
      "roleArn": "string"
    },
    "http": {
      "url": "string",
      "confirmationUrl": "string",
      "headers": [
        {
          "key": "string",
          "value": "string"
        }
        ...
      ],
      "auth": {
        "sigv4": {
          "signingRegion": "string",
          "serviceName": "string",
          "roleArn": "string"
        }
      }
    }
  }
}

--tags (string)

Metadata which can be used to manage the topic rule.

Note

For URI Request parameters use format: ...key1=value1key2=value2...

For the CLI command-line parameter use format: --tags "key1=value1key2=value2..."

For the cli-input-json file use format: "tags": "key1=value1key2=value2..."

--cli-input-json (string) Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See 'aws help' for descriptions of global parameters.

Examples

To create a rule that sends an Amazon SNS alert

The following create-topic-rule example creates a rule that sends an Amazon SNS message when soil moisture level readings, as found in a device shadow, are low.

aws iot create-topic-rule \
    --rule-name "LowMoistureRule" \
    --topic-rule-payload file://plant-rule.json

The example requires the following JSON code to be saved to a file named plant-rule.json:

{
    "sql": "SELECT * FROM '$aws/things/MyRPi/shadow/update/accepted' WHERE state.reported.moisture = 'low'\n",
    "description": "Sends an alert whenever soil moisture level readings are too low.",
    "ruleDisabled": false,
    "awsIotSqlVersion": "2016-03-23",
    "actions": [{
            "sns": {
                "targetArn": "arn:aws:sns:us-west-2:123456789012:MyRPiLowMoistureTopic",
                "roleArn": "arn:aws:iam::123456789012:role/service-role/MyRPiLowMoistureTopicRole",
                "messageFormat": "RAW"
            }
    }]
}

This command produces no output.

For more information, see Creating an AWS IoT Rule in the AWS IoT Developers Guide.

Output

None