Skip to content
v2.277.0

Experimental

@aws-cdk/aws-iot-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

IotSql Class ​

Defines AWS IoT SQL.

Example ​

ts
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
    }),
  ],
});
python
import aws_cdk.aws_sns as sns


topic = sns.Topic(self, "MyTopic")

topic_rule = iot.TopicRule(self, "TopicRule",
    sql=iot.IotSql.from_string_as_ver20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"),
    actions=[
        actions.SnsTopicAction(topic,
            message_format=actions.SnsActionMessageFormat.JSON
        )
    ]
)
java
import software.amazon.awscdk.services.sns.*;


Topic topic = new Topic(this, "MyTopic");

TopicRule topicRule = TopicRule.Builder.create(this, "TopicRule")
        .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"))
        .actions(List.of(
            SnsTopicAction.Builder.create(topic)
                    .messageFormat(SnsActionMessageFormat.JSON)
                    .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.IoT.Alpha
using Amazon.CDK.AWS.SNS;


var topic = new Topic(this, "MyTopic");

var topicRule = new TopicRule(this, "TopicRule", new TopicRuleProps {
    Sql = IotSql.FromStringAsVer20160323("SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'"),
    Actions = new [] {
        new SnsTopicAction(topic, new SnsTopicActionProps {
            MessageFormat = SnsActionMessageFormat.JSON
        }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdkiotalpha/v2
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,
		}),
	},
})

Initializer ​

ts
new IotSql()
python
IotSql()
java
new IotSql()
csharp
new IotSql()
go
NewIotSql()

Methods ​

bind(scope: Construct): IotSqlConfigdef bind(self, scope: Construct) -> IotSqlConfigpublic IotSqlConfig bind(Construct scope)public IotSqlConfig Bind(Construct scope)func Bind(Scope Construct) IotSqlConfig#
Returns the IoT SQL configuration.
fromStringAsVer20151008(sql: string): IotSql // chainable@staticmethod def from_string_as_ver20151008(sql: str) -> IotSqlpublic static IotSql fromStringAsVer20151008(String sql)public static IotSql FromStringAsVer20151008(string sql)func FromStringAsVer20151008(Sql *string) IotSqlstatic#
Uses the original SQL version built on 2015-10-08.
1 parameter · returns

Parameters

  • sqlsqlsqlsqlSql — The actual SQL-like syntax query.

Returns: Instance of IotSql

fromStringAsVer20160323(sql: string): IotSql // chainable@staticmethod def from_string_as_ver20160323(sql: str) -> IotSqlpublic static IotSql fromStringAsVer20160323(String sql)public static IotSql FromStringAsVer20160323(string sql)func FromStringAsVer20160323(Sql *string) IotSqlstatic#
Uses the SQL version built on 2016-03-23.
1 parameter · returns

Parameters

  • sqlsqlsqlsqlSql — The actual SQL-like syntax query.

Returns: Instance of IotSql

fromStringAsVerNewestUnstable(sql: string): IotSql // chainable@staticmethod def from_string_as_ver_newest_unstable(sql: str) -> IotSqlpublic static IotSql fromStringAsVerNewestUnstable(String sql)public static IotSql FromStringAsVerNewestUnstable(string sql)func FromStringAsVerNewestUnstable(Sql *string) IotSqlstatic#
Uses the most recent beta SQL version.

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

1 parameter · returns

Parameters

  • sqlsqlsqlsqlSql — The actual SQL-like syntax query.

Returns: Instance of IotSql