Package software.amazon.awscdk.services.iot.alpha
AWS IoT Construct Library
---
The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.
AWS IoT Core lets you connect billions of IoT devices and route trillions of messages to AWS services without managing infrastructure.
TopicRule
Create a topic rule that give your devices the ability to interact with AWS services. You can create a topic rule with an action that invoke the Lambda action as following:
Function func = Function.Builder.create(this, "MyFunction") .runtime(Runtime.NODEJS_LATEST) .handler("index.handler") .code(Code.fromInline("\n exports.handler = (event) => {\n console.log(\"It is test for lambda action of AWS IoT Rule.\", event);\n };")) .build(); TopicRule.Builder.create(this, "TopicRule") .topicRuleName("MyTopicRule") // optional .description("invokes the lambda function") // optional .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")) .actions(List.of(new LambdaFunctionAction(func))) .build();
Or, you can add an action after constructing the TopicRule
instance as following:
Function func; TopicRule topicRule = TopicRule.Builder.create(this, "TopicRule") .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")) .build(); topicRule.addAction(new LambdaFunctionAction(func));
You can also supply errorAction
as following,
and the IoT Rule will trigger it if a rule's action is unable to perform:
import software.amazon.awscdk.services.logs.*; LogGroup logGroup = new LogGroup(this, "MyLogGroup"); TopicRule.Builder.create(this, "TopicRule") .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")) .errorAction(new CloudWatchLogsAction(logGroup)) .build();
If you wanna make the topic rule disable, add property enabled: false
as following:
TopicRule.Builder.create(this, "TopicRule") .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")) .enabled(false) .build();
See also @aws-cdk/aws-iot-actions-alpha for other actions.
-
ClassDescription(experimental) Properties for an topic rule action.A builder for
ActionConfig
An implementation forActionConfig
(experimental) An abstract action for TopicRule.Internal default implementation forIAction
.A proxy class which represents a concrete javascript instance of this type.(experimental) Defines AWS IoT SQL.(experimental) The type returned from thebind()
method inIotSql
.A builder forIotSqlConfig
An implementation forIotSqlConfig
(experimental) Represents an AWS IoT Rule.Internal default implementation forITopicRule
.A proxy class which represents a concrete javascript instance of this type.(experimental) Defines an AWS IoT Rule in this stack.(experimental) A fluent builder forTopicRule
.(experimental) Properties for defining an AWS IoT Rule.A builder forTopicRuleProps
An implementation forTopicRuleProps