@aws-cdk_aws-iot-alpha.TopicRule

class TopicRule (construct) ๐Ÿ”น

LanguageType name
.NETAmazon.CDK.AWS.IoT.Alpha.TopicRule
Gogithub.com/aws/aws-cdk-go/awscdkiotalpha/v2#TopicRule
Javasoftware.amazon.awscdk.services.iot.alpha.TopicRule
Pythonaws_cdk.aws_iot_alpha.TopicRule
TypeScript (source)@aws-cdk/aws-iot-alpha ยป TopicRule

Implements IConstruct, IDependable, IResource, ITopicRule

Defines an AWS IoT Rule in this stack.

Example

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
    }),
  ],
});

Initializer

new TopicRule(scope: Construct, id: string, props: TopicRuleProps)

Parameters

  • scope Construct
  • id string
  • props TopicRuleProps

Construct Props

NameTypeDescription
sql๐Ÿ”นIotSqlA simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere.
actions?๐Ÿ”นIAction[]The actions associated with the topic rule.
description?๐Ÿ”นstringA textual description of the topic rule.
enabled?๐Ÿ”นbooleanSpecifies whether the rule is enabled.
errorAction?๐Ÿ”นIActionThe action AWS IoT performs when it is unable to perform a rule's action.
topicRuleName?๐Ÿ”นstringThe name of the topic rule.

sql๐Ÿ”น

Type: IotSql

A simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere.

See also: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html


actions?๐Ÿ”น

Type: IAction[] (optional, default: No actions will be perform)

The actions associated with the topic rule.


description?๐Ÿ”น

Type: string (optional, default: None)

A textual description of the topic rule.


enabled?๐Ÿ”น

Type: boolean (optional, default: true)

Specifies whether the rule is enabled.


errorAction?๐Ÿ”น

Type: IAction (optional, default: no action will be performed)

The action AWS IoT performs when it is unable to perform a rule's action.


topicRuleName?๐Ÿ”น

Type: string (optional, default: None)

The name of the topic rule.

Properties

NameTypeDescription
env๐Ÿ”นResourceEnvironmentThe environment this resource belongs to.
node๐Ÿ”นNodeThe tree node.
stack๐Ÿ”นStackThe stack in which this resource is defined.
topicRuleArn๐Ÿ”นstringArn of this topic rule.
topicRuleName๐Ÿ”นstringName of this topic rule.

env๐Ÿ”น

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node๐Ÿ”น

Type: Node

The tree node.


stack๐Ÿ”น

Type: Stack

The stack in which this resource is defined.


topicRuleArn๐Ÿ”น

Type: string

Arn of this topic rule.


topicRuleName๐Ÿ”น

Type: string

Name of this topic rule.

Methods

NameDescription
addAction(action)๐Ÿ”นAdd a action to the topic rule.
applyRemovalPolicy(policy)๐Ÿ”นApply the given removal policy to this resource.
toString()๐Ÿ”นReturns a string representation of this construct.
static fromTopicRuleArn(scope, id, topicRuleArn)๐Ÿ”นImport an existing AWS IoT Rule provided an ARN.

addAction(action)๐Ÿ”น

public addAction(action: IAction): void

Parameters

  • action IAction โ€” the action to associate with the topic rule.

Add a action to the topic rule.


applyRemovalPolicy(policy)๐Ÿ”น

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()๐Ÿ”น

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromTopicRuleArn(scope, id, topicRuleArn)๐Ÿ”น

public static fromTopicRuleArn(scope: Construct, id: string, topicRuleArn: string): ITopicRule

Parameters

  • scope Construct โ€” The parent creating construct (usually this).
  • id string โ€” The construct's name.
  • topicRuleArn string โ€” AWS IoT Rule ARN (i.e. arn:aws:iot::<account-id>:rule/MyRule).

Returns

  • ITopicRule

Import an existing AWS IoT Rule provided an ARN.