Skip to content
v2.277.0

Experimental

@aws-cdk/aws-iot-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

TopicRuleProps Struct ​

Properties for defining an AWS IoT Rule.

Example ​

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
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
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();
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
        }) }
});
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 ​

actionsoptionalIAction[]actionsoptionaltyping.List[IAction]actionsoptionalList<IAction>ActionsoptionalIAction[]Actionsoptional*[]IAction#
The actions associated with the topic rule.

Default: No actions will be perform

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string= None#
A textual description of the topic rule.
enabledoptionalbooleanenabledoptionalboolenabledoptionalBooleanEnabledoptionalboolEnabledoptional*bool= true#
Specifies whether the rule is enabled.
errorActionoptionalIActionerror_actionoptionalIActionerrorActionoptionalIActionErrorActionoptionalIActionErrorActionoptionalIAction#
The action AWS IoT performs when it is unable to perform a rule's action.

Default: no action will be performed

sqlIotSqlsqlIotSqlsqlIotSqlSqlIotSqlSqlIotSqlrequired#
A simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere.
topicRuleNameoptionalstringtopic_rule_nameoptionalstrtopicRuleNameoptionalStringTopicRuleNameoptionalstringTopicRuleNameoptional*string= None#
The name of the topic rule.