awscdkiotalpha

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

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 8 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.

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:

func := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromInline(jsii.String(`
	    exports.handler = (event) => {
	      console.log("It is test for lambda action of AWS IoT Rule.", event);
	    };`)),
})

iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	TopicRuleName: jsii.String("MyTopicRule"),
	 // optional
	Description: jsii.String("invokes the lambda function"),
	 // optional
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")),
	Actions: []iAction{
		actions.NewLambdaFunctionAction(func),
	},
})

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

var func function


topicRule := iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")),
})
topicRule.AddAction(actions.NewLambdaFunctionAction(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 logs "github.com/aws/aws-cdk-go/awscdk"


logGroup := logs.NewLogGroup(this, jsii.String("MyLogGroup"))

iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")),
	ErrorAction: actions.NewCloudWatchLogsAction(logGroup),
})

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

iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, timestamp() as timestamp FROM 'device/+/data'")),
	Enabled: jsii.Boolean(false),
})

See also @aws-cdk/aws-iot-actions-alpha 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.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`. Experimental.

func TopicRule_IsOwnedResource

func TopicRule_IsOwnedResource(construct constructs.IConstruct) *bool

Returns true if the construct was created by CDK, and false otherwise. Experimental.

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 `field:"required" json:"configuration" yaml:"configuration"`
}

Properties for an topic rule action.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import iot_alpha "github.com/aws/aws-cdk-go/awscdkiotalpha"

actionConfig := &ActionConfig{
	Configuration: &ActionProperty{
		CloudwatchAlarm: &CloudwatchAlarmActionProperty{
			AlarmName: jsii.String("alarmName"),
			RoleArn: jsii.String("roleArn"),
			StateReason: jsii.String("stateReason"),
			StateValue: jsii.String("stateValue"),
		},
		CloudwatchLogs: &CloudwatchLogsActionProperty{
			LogGroupName: jsii.String("logGroupName"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			BatchMode: jsii.Boolean(false),
		},
		CloudwatchMetric: &CloudwatchMetricActionProperty{
			MetricName: jsii.String("metricName"),
			MetricNamespace: jsii.String("metricNamespace"),
			MetricUnit: jsii.String("metricUnit"),
			MetricValue: jsii.String("metricValue"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			MetricTimestamp: jsii.String("metricTimestamp"),
		},
		DynamoDb: &DynamoDBActionProperty{
			HashKeyField: jsii.String("hashKeyField"),
			HashKeyValue: jsii.String("hashKeyValue"),
			RoleArn: jsii.String("roleArn"),
			TableName: jsii.String("tableName"),

			// the properties below are optional
			HashKeyType: jsii.String("hashKeyType"),
			PayloadField: jsii.String("payloadField"),
			RangeKeyField: jsii.String("rangeKeyField"),
			RangeKeyType: jsii.String("rangeKeyType"),
			RangeKeyValue: jsii.String("rangeKeyValue"),
		},
		DynamoDBv2: &DynamoDBv2ActionProperty{
			PutItem: &PutItemInputProperty{
				TableName: jsii.String("tableName"),
			},
			RoleArn: jsii.String("roleArn"),
		},
		Elasticsearch: &ElasticsearchActionProperty{
			Endpoint: jsii.String("endpoint"),
			Id: jsii.String("id"),
			Index: jsii.String("index"),
			RoleArn: jsii.String("roleArn"),
			Type: jsii.String("type"),
		},
		Firehose: &FirehoseActionProperty{
			DeliveryStreamName: jsii.String("deliveryStreamName"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			BatchMode: jsii.Boolean(false),
			Separator: jsii.String("separator"),
		},
		Http: &HttpActionProperty{
			Url: jsii.String("url"),

			// the properties below are optional
			Auth: &HttpAuthorizationProperty{
				Sigv4: &SigV4AuthorizationProperty{
					RoleArn: jsii.String("roleArn"),
					ServiceName: jsii.String("serviceName"),
					SigningRegion: jsii.String("signingRegion"),
				},
			},
			ConfirmationUrl: jsii.String("confirmationUrl"),
			Headers: []interface{}{
				&HttpActionHeaderProperty{
					Key: jsii.String("key"),
					Value: jsii.String("value"),
				},
			},
		},
		IotAnalytics: &IotAnalyticsActionProperty{
			ChannelName: jsii.String("channelName"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			BatchMode: jsii.Boolean(false),
		},
		IotEvents: &IotEventsActionProperty{
			InputName: jsii.String("inputName"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			BatchMode: jsii.Boolean(false),
			MessageId: jsii.String("messageId"),
		},
		IotSiteWise: &IotSiteWiseActionProperty{
			PutAssetPropertyValueEntries: []interface{}{
				&PutAssetPropertyValueEntryProperty{
					PropertyValues: []interface{}{
						&AssetPropertyValueProperty{
							Timestamp: &AssetPropertyTimestampProperty{
								TimeInSeconds: jsii.String("timeInSeconds"),

								// the properties below are optional
								OffsetInNanos: jsii.String("offsetInNanos"),
							},
							Value: &AssetPropertyVariantProperty{
								BooleanValue: jsii.String("booleanValue"),
								DoubleValue: jsii.String("doubleValue"),
								IntegerValue: jsii.String("integerValue"),
								StringValue: jsii.String("stringValue"),
							},

							// the properties below are optional
							Quality: jsii.String("quality"),
						},
					},

					// the properties below are optional
					AssetId: jsii.String("assetId"),
					EntryId: jsii.String("entryId"),
					PropertyAlias: jsii.String("propertyAlias"),
					PropertyId: jsii.String("propertyId"),
				},
			},
			RoleArn: jsii.String("roleArn"),
		},
		Kafka: &KafkaActionProperty{
			ClientProperties: map[string]*string{
				"clientPropertiesKey": jsii.String("clientProperties"),
			},
			DestinationArn: jsii.String("destinationArn"),
			Topic: jsii.String("topic"),

			// the properties below are optional
			Headers: []interface{}{
				&KafkaActionHeaderProperty{
					Key: jsii.String("key"),
					Value: jsii.String("value"),
				},
			},
			Key: jsii.String("key"),
			Partition: jsii.String("partition"),
		},
		Kinesis: &KinesisActionProperty{
			RoleArn: jsii.String("roleArn"),
			StreamName: jsii.String("streamName"),

			// the properties below are optional
			PartitionKey: jsii.String("partitionKey"),
		},
		Lambda: &LambdaActionProperty{
			FunctionArn: jsii.String("functionArn"),
		},
		Location: &LocationActionProperty{
			DeviceId: jsii.String("deviceId"),
			Latitude: jsii.String("latitude"),
			Longitude: jsii.String("longitude"),
			RoleArn: jsii.String("roleArn"),
			TrackerName: jsii.String("trackerName"),

			// the properties below are optional
			Timestamp: &TimestampProperty{
				Value: jsii.String("value"),

				// the properties below are optional
				Unit: jsii.String("unit"),
			},
		},
		OpenSearch: &OpenSearchActionProperty{
			Endpoint: jsii.String("endpoint"),
			Id: jsii.String("id"),
			Index: jsii.String("index"),
			RoleArn: jsii.String("roleArn"),
			Type: jsii.String("type"),
		},
		Republish: &RepublishActionProperty{
			RoleArn: jsii.String("roleArn"),
			Topic: jsii.String("topic"),

			// the properties below are optional
			Headers: &RepublishActionHeadersProperty{
				ContentType: jsii.String("contentType"),
				CorrelationData: jsii.String("correlationData"),
				MessageExpiry: jsii.String("messageExpiry"),
				PayloadFormatIndicator: jsii.String("payloadFormatIndicator"),
				ResponseTopic: jsii.String("responseTopic"),
				UserProperties: []interface{}{
					&UserPropertyProperty{
						Key: jsii.String("key"),
						Value: jsii.String("value"),
					},
				},
			},
			Qos: jsii.Number(123),
		},
		S3: &S3ActionProperty{
			BucketName: jsii.String("bucketName"),
			Key: jsii.String("key"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			CannedAcl: jsii.String("cannedAcl"),
		},
		Sns: &SnsActionProperty{
			RoleArn: jsii.String("roleArn"),
			TargetArn: jsii.String("targetArn"),

			// the properties below are optional
			MessageFormat: jsii.String("messageFormat"),
		},
		Sqs: &SqsActionProperty{
			QueueUrl: jsii.String("queueUrl"),
			RoleArn: jsii.String("roleArn"),

			// the properties below are optional
			UseBase64: jsii.Boolean(false),
		},
		StepFunctions: &StepFunctionsActionProperty{
			RoleArn: jsii.String("roleArn"),
			StateMachineName: jsii.String("stateMachineName"),

			// the properties below are optional
			ExecutionNamePrefix: jsii.String("executionNamePrefix"),
		},
		Timestream: &TimestreamActionProperty{
			DatabaseName: jsii.String("databaseName"),
			Dimensions: []interface{}{
				&TimestreamDimensionProperty{
					Name: jsii.String("name"),
					Value: jsii.String("value"),
				},
			},
			RoleArn: jsii.String("roleArn"),
			TableName: jsii.String("tableName"),

			// the properties below are optional
			Timestamp: &TimestreamTimestampProperty{
				Unit: jsii.String("unit"),
				Value: jsii.String("value"),
			},
		},
	},
}

Experimental.

type IAction

type IAction interface {
}

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 {
	// Returns the IoT SQL configuration.
	// Experimental.
	Bind(scope constructs.Construct) *IotSqlConfig
}

Defines AWS IoT SQL.

Example:

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

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 `field:"required" json:"awsIotSqlVersion" yaml:"awsIotSqlVersion"`
	// The SQL statement used to query the topic.
	// Experimental.
	Sql *string `field:"required" json:"sql" yaml:"sql"`
}

The type returned from the `bind()` method in `IotSql`.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import iot_alpha "github.com/aws/aws-cdk-go/awscdkiotalpha"

iotSqlConfig := &IotSqlConfig{
	AwsIotSqlVersion: jsii.String("awsIotSqlVersion"),
	Sql: jsii.String("sql"),
}

Experimental.

type TopicRule

type TopicRule interface {
	awscdk.Resource
	ITopicRule
	// 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.
	// Experimental.
	Env() *awscdk.ResourceEnvironment
	// The tree node.
	// Experimental.
	Node() constructs.Node
	// Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.
	//
	// This value will resolve to one of the following:
	// - a concrete value (e.g. `"my-awesome-bucket"`)
	// - `undefined`, when a name should be generated by CloudFormation
	// - a concrete name generated automatically during synthesis, in
	//   cross-environment scenarios.
	// Experimental.
	PhysicalName() *string
	// The stack in which this resource is defined.
	// Experimental.
	Stack() awscdk.Stack
	// Arn of this topic rule.
	// Experimental.
	TopicRuleArn() *string
	// Name of this topic rule.
	// Experimental.
	TopicRuleName() *string
	// Add a action to the topic rule.
	// Experimental.
	AddAction(action IAction)
	// 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`).
	// Experimental.
	ApplyRemovalPolicy(policy awscdk.RemovalPolicy)
	// Experimental.
	GeneratePhysicalName() *string
	// Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. `bucket.bucketArn`).
	//
	// Normally, this token will resolve to `arnAttr`, but if the resource is
	// referenced across environments, `arnComponents` will be used to synthesize
	// a concrete ARN with the resource's physical name. Make sure to reference
	// `this.physicalName` in `arnComponents`.
	// Experimental.
	GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string
	// Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. `bucket.bucketName`).
	//
	// Normally, this token will resolve to `nameAttr`, but if the resource is
	// referenced across environments, it will be resolved to `this.physicalName`,
	// which will be a concrete name.
	// Experimental.
	GetResourceNameAttribute(nameAttr *string) *string
	// Returns a string representation of this construct.
	// Experimental.
	ToString() *string
}

Defines an AWS IoT Rule in this stack.

Example:

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

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 `field:"required" json:"sql" yaml:"sql"`
	// The actions associated with the topic rule.
	// Default: No actions will be perform.
	//
	// Experimental.
	Actions *[]IAction `field:"optional" json:"actions" yaml:"actions"`
	// A textual description of the topic rule.
	// Default: None.
	//
	// Experimental.
	Description *string `field:"optional" json:"description" yaml:"description"`
	// Specifies whether the rule is enabled.
	// Default: true.
	//
	// Experimental.
	Enabled *bool `field:"optional" json:"enabled" yaml:"enabled"`
	// The action AWS IoT performs when it is unable to perform a rule's action.
	// Default: - no action will be performed.
	//
	// Experimental.
	ErrorAction IAction `field:"optional" json:"errorAction" yaml:"errorAction"`
	// The name of the topic rule.
	// Default: None.
	//
	// Experimental.
	TopicRuleName *string `field:"optional" json:"topicRuleName" yaml:"topicRuleName"`
}

Properties for defining an AWS IoT Rule.

Example:

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

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