> **Experimental**
>
> `@aws-cdk/aws-iot-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# TopicRuleProps

Properties for defining an AWS IoT Rule.

Used as props by: [TopicRule](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-alpha.TopicRule.html)

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`lib/topic-rule.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/@aws-cdk/aws-iot-alpha/lib/topic-rule.ts#L35)

## Example

TypeScript:

```ts
import * as sns from 'aws-cdk-lib/aws-sns';

const topic = new sns.Topic(this, 'MyTopic');

const topicRule = new iot.TopicRule(this, 'TopicRule', {
  sql: iot.IotSql.fromStringAsVer20160323(
    "SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'",
  ),
  actions: [
    new actions.SnsTopicAction(topic, {
      messageFormat: actions.SnsActionMessageFormat.JSON, // optional property, default is SnsActionMessageFormat.RAW
    }),
  ],
});
```

Python:

```python
import aws_cdk.aws_sns as sns

topic = sns.Topic(self, "MyTopic")

topic_rule = iot.TopicRule(self, "TopicRule",
    sql=iot.IotSql.from_string_as_ver20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"),
    actions=[
        actions.SnsTopicAction(topic,
            message_format=actions.SnsActionMessageFormat.JSON
        )
    ]
)
```

Java:

```java
import software.amazon.awscdk.services.sns.*;

Topic topic = new Topic(this, "MyTopic");

TopicRule topicRule = TopicRule.Builder.create(this, "TopicRule")
        .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"))
        .actions(List.of(
            SnsTopicAction.Builder.create(topic)
                    .messageFormat(SnsActionMessageFormat.JSON)
                    .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.AWS.IoT.Alpha
using Amazon.CDK.AWS.SNS;

var topic = new Topic(this, "MyTopic");

var topicRule = new TopicRule(this, "TopicRule", new TopicRuleProps {
    Sql = IotSql.FromStringAsVer20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"),
    Actions = new [] {
        new SnsTopicAction(topic, new SnsTopicActionProps {
            MessageFormat = SnsActionMessageFormat.JSON
        }) }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdkiotalpha/v2
import sns "github.com/aws/aws-cdk-go/awscdk"

topic := sns.NewTopic(this, jsii.String("MyTopic"))

topicRule := iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'")),
	Actions: []IAction{
		actions.NewSnsTopicAction(topic, &SnsTopicActionProps{
			MessageFormat: actions.SnsActionMessageFormat_JSON,
		}),
	},
})
```

## Properties

- `actions`: [IAction](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-alpha.IAction.html)[] — The actions associated with the topic rule.

  **Default:** No actions will be perform

- `description`: string = None — A textual description of the topic rule.

- `enabled`: boolean = true — Specifies whether the rule is enabled.

- `errorAction`: [IAction](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-alpha.IAction.html) — The action AWS IoT performs when it is unable to perform a rule's action.

  **Default:** no action will be performed

- `sql`: [IotSql](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-alpha.IotSql.html) (required) — A simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere.

- `topicRuleName`: string = None — The name of the topic rule.
