awscdkiotalpha

package module
v2.1.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

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.

Installation

Install the module:

$ npm i @aws-cdk/aws-iot

Import it into your code:

import * as iot from '@aws-cdk/aws-iot-alpha';

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:

import * as iot from '@aws-cdk/aws-iot-alpha';
import * as actions from '@aws-cdk/aws-iot-actions-alpha';
import * as lambda from 'aws-cdk-lib/aws-lambda';

const func = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.NODEJS_14_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline(`
    exports.handler = (event) => {
      console.log("It is test for lambda action of AWS IoT Rule.", event);
    };`
  ),
});

new iot.TopicRule(this, 'TopicRule', {
  topicRuleName: 'MyTopicRule', // optional
  description: 'invokes the lambda function', // optional
  sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"),
  actions: [new actions.LambdaFunctionAction(func)],
});

Or, you can add an action after constructing the TopicRule instance as following:

const topicRule = new iot.TopicRule(this, 'TopicRule', {
  sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"),
});
topicRule.addAction(new actions.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 * as iot from '@aws-cdk/aws-iot-alpha';
import * as actions from '@aws-cdk/aws-iot-actions-alpha';
import * as logs from 'aws-cdk-lib/aws-logs';

const logGroup = new logs.LogGroup(this, 'MyLogGroup');

new iot.TopicRule(this, 'TopicRule', {
  sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"),
  errorAction: new actions.CloudWatchLogsAction(logGroup),
});

If you wanna make the topic rule disable, add property enabled: false as following:

new iot.TopicRule(this, 'TopicRule', {
  sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'"),
  enabled: false,
});

See also @aws-cdk/aws-iot-actions for other actions.

Documentation

Overview

The CDK Construct Library for AWS::IoT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIotSql_Override

func NewIotSql_Override(i IotSql)

Experimental.

func NewTopicRule_Override

func NewTopicRule_Override(t TopicRule, scope constructs.Construct, id *string, props *TopicRuleProps)

Experimental.

func TopicRule_IsConstruct

func TopicRule_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Returns: true if `x` is an object created from a class which extends `Construct`. Deprecated: use `x instanceof Construct` instead

func TopicRule_IsResource

func TopicRule_IsResource(construct constructs.IConstruct) *bool

Check whether the given construct is a Resource. Experimental.

Types

type ActionConfig

type ActionConfig struct {
	// The configuration for this action.
	// Experimental.
	Configuration *awsiot.CfnTopicRule_ActionProperty `json:"configuration"`
}

Properties for an topic rule action.

TODO: EXAMPLE

Experimental.

type IAction

type IAction interface {
	// Returns the topic rule action specification.
	// Experimental.
	Bind(topicRule ITopicRule) *ActionConfig
}

An abstract action for TopicRule. Experimental.

type ITopicRule

type ITopicRule interface {
	awscdk.IResource
	// The value of the topic rule Amazon Resource Name (ARN), such as arn:aws:iot:us-east-2:123456789012:rule/rule_name.
	// Experimental.
	TopicRuleArn() *string
	// The name topic rule.
	// Experimental.
	TopicRuleName() *string
}

Represents an AWS IoT Rule. Experimental.

func TopicRule_FromTopicRuleArn

func TopicRule_FromTopicRuleArn(scope constructs.Construct, id *string, topicRuleArn *string) ITopicRule

Import an existing AWS IoT Rule provided an ARN. Experimental.

type IotSql

type IotSql interface {
	Bind(scope constructs.Construct) *IotSqlConfig
}

Defines AWS IoT SQL.

TODO: EXAMPLE

Experimental.

func IotSql_FromStringAsVer20151008

func IotSql_FromStringAsVer20151008(sql *string) IotSql

Uses the original SQL version built on 2015-10-08.

Returns: Instance of IotSql Experimental.

func IotSql_FromStringAsVer20160323

func IotSql_FromStringAsVer20160323(sql *string) IotSql

Uses the SQL version built on 2016-03-23.

Returns: Instance of IotSql Experimental.

func IotSql_FromStringAsVerNewestUnstable

func IotSql_FromStringAsVerNewestUnstable(sql *string) IotSql

Uses the most recent beta SQL version.

If you use this version, it might introduce breaking changes to your rules.

Returns: Instance of IotSql Experimental.

type IotSqlConfig

type IotSqlConfig struct {
	// The version of the SQL rules engine to use when evaluating the rule.
	// Experimental.
	AwsIotSqlVersion *string `json:"awsIotSqlVersion"`
	// The SQL statement used to query the topic.
	// Experimental.
	Sql *string `json:"sql"`
}

The type returned from the `bind()` method in {@link IotSql}.

TODO: EXAMPLE

Experimental.

type TopicRule

type TopicRule interface {
	awscdk.Resource
	ITopicRule
	Env() *awscdk.ResourceEnvironment
	Node() constructs.Node
	PhysicalName() *string
	Stack() awscdk.Stack
	TopicRuleArn() *string
	TopicRuleName() *string
	AddAction(action IAction)
	ApplyRemovalPolicy(policy awscdk.RemovalPolicy)
	GeneratePhysicalName() *string
	GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string
	GetResourceNameAttribute(nameAttr *string) *string
	ToString() *string
}

Defines an AWS IoT Rule in this stack.

TODO: EXAMPLE

Experimental.

func NewTopicRule

func NewTopicRule(scope constructs.Construct, id *string, props *TopicRuleProps) TopicRule

Experimental.

type TopicRuleProps

type TopicRuleProps struct {
	// A simplified SQL syntax to filter messages received on an MQTT topic and push the data elsewhere.
	// See: https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html
	//
	// Experimental.
	Sql IotSql `json:"sql"`
	// The actions associated with the topic rule.
	// Experimental.
	Actions *[]IAction `json:"actions"`
	// A textual description of the topic rule.
	// Experimental.
	Description *string `json:"description"`
	// Specifies whether the rule is enabled.
	// Experimental.
	Enabled *bool `json:"enabled"`
	// The action AWS IoT performs when it is unable to perform a rule's action.
	// Experimental.
	ErrorAction IAction `json:"errorAction"`
	// The name of the topic rule.
	// Experimental.
	TopicRuleName *string `json:"topicRuleName"`
}

Properties for defining an AWS IoT Rule.

TODO: EXAMPLE

Experimental.

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL