AWS CDK AWS IoT Actions Alpha

2.250.0a0 · active · verified Thu Apr 16

The `aws-cdk-aws-iot-actions-alpha` library provides integration classes for defining receipt rule actions for AWS IoT Core topic rules. Being an 'alpha' package, its APIs are experimental and under active development, meaning they are subject to non-backward compatible changes or removal in future versions without adhering to semantic versioning. It allows connecting IoT messages to various AWS services like Lambda, S3, SQS, SNS, Kinesis, CloudWatch, and more. It is part of the AWS Cloud Development Kit (CDK) v2 ecosystem and is released frequently alongside other CDK modules.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an AWS IoT Topic Rule that automatically puts messages received on a specific MQTT topic into an Amazon S3 bucket using the `S3PutObjectAction` from `aws-cdk-aws-iot-actions-alpha`. It sets up a basic CDK application and stack, provisions an S3 bucket, and configures the IoT rule.

from aws_cdk import App, Stack, Duration
from aws_cdk.aws_s3 import Bucket
from aws_cdk.aws_iot import TopicRule, IotSql
from aws_cdk.aws_iot_actions_alpha import S3PutObjectAction

class MyIotStack(Stack):
    def __init__(self, scope: App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Create an S3 bucket to store IoT data
        bucket = Bucket(self, "MyIoTDataBucket")

        # Define an IoT Topic Rule with an S3 action
        # This rule will trigger when a message is published to 'device/+/data'
        # and put the message into the S3 bucket.
        topic_rule = TopicRule(
            self, "MyS3IotRule",
            sql=IotSql.from_string_as_ver20160323(
                "SELECT topic(2) as device_id, timestamp() as timestamp, * FROM 'device/+/data'"
            ),
            actions=[
                S3PutObjectAction(bucket)
            ]
        )

app = App()
MyIotStack(app, "MyIotS3IntegrationStack")
app.synth()

view raw JSON →