> **Experimental**
>
> `@aws-cdk/aws-iot-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# IotSql

Defines AWS IoT SQL.

Obtainable from: IotSql.fromStringAsVer20151008, IotSql.fromStringAsVer20160323, IotSql.fromStringAsVerNewestUnstable

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`lib/iot-sql.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-iot-alpha/lib/iot-sql.ts#L21)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
        }) }
});
```

Golang:

```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

TypeScript:

```ts
new IotSql()
```

Python:

```python
IotSql()
```

Java:

```java
new IotSql()
```

C# / .NET:

```csharp
new IotSql()
```

Golang:

```go
NewIotSql()
```

## Methods

- `bind(scope: Construct): IotSqlConfig` — Returns the IoT SQL configuration.

- `fromStringAsVer20151008(sql: string): IotSql // chainable` (static) — Uses the original SQL version built on 2015-10-08.

  **Parameters**

  - `sql` — The actual SQL-like syntax query.

  **Returns:** Instance of IotSql

- `fromStringAsVer20160323(sql: string): IotSql // chainable` (static) — Uses the SQL version built on 2016-03-23.

  **Parameters**

  - `sql` — The actual SQL-like syntax query.

  **Returns:** Instance of IotSql

- `fromStringAsVerNewestUnstable(sql: string): IotSql // chainable` (static) — Uses the most recent beta SQL version.

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

  **Parameters**

  - `sql` — The actual SQL-like syntax query.

  **Returns:** Instance of IotSql
