class TopicRule (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.IoT.TopicRule |
Java | software.amazon.awscdk.services.iot.TopicRule |
Python | aws_cdk.aws_iot.TopicRule |
TypeScript (source) | @aws-cdk/aws-iot ยป TopicRule |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, ITopic
Defines an AWS IoT Rule in this stack.
Example
const bucket = new s3.Bucket(this, 'MyBucket');
new iot.TopicRule(this, 'TopicRule', {
sql: iot.IotSql.fromStringAsVer20160323("SELECT * FROM 'device/+/data'"),
actions: [
new actions.S3PutObjectAction(bucket, {
accessControl: s3.BucketAccessControl.PUBLIC_READ,
}),
],
});
Initializer
new TopicRule(scope: Construct, id: string, props: TopicRuleProps)
Parameters
- scope
Construct
- id
string
- props
Topic
Rule Props
Construct Props
Name | Type | Description |
---|---|---|
sql | Iot | A 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? | string | A textual description of the topic rule. |
enabled? | boolean | Specifies whether the rule is enabled. |
error | IAction | The action AWS IoT performs when it is unable to perform a rule's action. |
topic | string | The name of the topic rule. |
sql
Type:
Iot
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
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
topic | string | Arn of this topic rule. |
topic | string | Name of this topic rule. |
env
Type:
Resource
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:
Construct
The construct tree node associated with this construct.
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
Name | Description |
---|---|
add | Add a action to the topic rule. |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | 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
Removal
Policy
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 (usuallythis
). - id
string
โ The construct's name. - topicRuleArn
string
โ AWS IoT Rule ARN (i.e. arn:aws:iot::<account-id>:rule/MyRule).
Returns
Import an existing AWS IoT Rule provided an ARN.