Skip to main content

Receipt Detector Model actions for AWS IoT Events

Project description

Actions for AWS::IoTEvents Detector Model

---

cdk-constructs: Experimental

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.


This library contains integration classes to specify actions of state events of Detector Model in @aws-cdk/aws-iotevents-alpha. Instances of these classes should be passed to State defined in @aws-cdk/aws-iotevents-alpha You can define built-in actions to use a timer or set a variable, or send data to other AWS resources.

This library contains integration classes to use a timer or set a variable, or send data to other AWS resources. AWS IoT Events can trigger actions when it detects a specified event or transition event.

Currently supported are:

  • Use timer
  • Set variable to detector instance
  • Invoke a Lambda function

Use timer

The code snippet below creates an Action that creates the timer with duration in seconds.

# Example automatically generated from non-compiling source. May contain errors.
import aws_cdk.aws_iotevents_alpha as iotevents
import aws_cdk.aws_iotevents_actions_alpha as actions

# input: iotevents.IInput

state = iotevents.State(
    state_name="MyState",
    on_enter=[iotevents.Event(
        event_name="test-event",
        condition=iotevents.Expression.current_input(input),
        actions=[
            actions.SetTimerAction("MyTimer", {
                "duration": cdk.Duration.seconds(60)
            })
        ]
    )]
)

Setting duration by IoT Events Expression:

# Example automatically generated from non-compiling source. May contain errors.
actions.SetTimerAction("MyTimer",
    duration_expression=iotevents.Expression.input_attribute(input, "payload.durationSeconds")
)

And the timer can be reset and cleared. Below is an example of general Device HeartBeat Detector Model:

# Example automatically generated from non-compiling source. May contain errors.
online = iotevents.State(
    state_name="Online",
    on_enter=[{
        "event_name": "enter-event",
        "condition": iotevents.Expression.current_input(input),
        "actions": [
            actions.SetTimerAction("MyTimer",
                duration=cdk.Duration.seconds(60)
            )
        ]
    }],
    on_input=[{
        "event_name": "input-event",
        "condition": iotevents.Expression.current_input(input),
        "actions": [
            actions.ResetTimerAction("MyTimer")
        ]
    }],
    on_exit=[{
        "event_name": "exit-event",
        "actions": [
            actions.ClearTimerAction("MyTimer")
        ]
    }]
)
offline = iotevents.State(state_name="Offline")

online.transition_to(offline, when=iotevents.Expression.timeout("MyTimer"))
offline.transition_to(online, when=iotevents.Expression.current_input(input))

Set variable to detector instance

The code snippet below creates an Action that set variable to detector instance when it is triggered.

import aws_cdk.aws_iotevents_alpha as iotevents
import aws_cdk.aws_iotevents_actions_alpha as actions

# input: iotevents.IInput

state = iotevents.State(
    state_name="MyState",
    on_enter=[iotevents.Event(
        event_name="test-event",
        condition=iotevents.Expression.current_input(input),
        actions=[
            actions.SetVariableAction("MyVariable",
                iotevents.Expression.input_attribute(input, "payload.temperature"))
        ]
    )]
)

Invoke a Lambda function

The code snippet below creates an Action that invoke a Lambda function when it is triggered.

import aws_cdk.aws_iotevents_alpha as iotevents
import aws_cdk.aws_iotevents_actions_alpha as actions
import aws_cdk.aws_lambda as lambda_

# input: iotevents.IInput
# func: lambda.IFunction

state = iotevents.State(
    state_name="MyState",
    on_enter=[iotevents.Event(
        event_name="test-event",
        condition=iotevents.Expression.current_input(input),
        actions=[actions.LambdaInvokeAction(func)]
    )]
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file aws_cdk_aws_iotevents_actions_alpha-2.163.1a0.tar.gz.

File metadata

File hashes

Hashes for aws_cdk_aws_iotevents_actions_alpha-2.163.1a0.tar.gz
Algorithm Hash digest
SHA256 44959eb535f35f4756eb5eb3c1825c1dcb0c9020cbcce61c5094fcc61d1c2a4d
MD5 c8af5b5bcb46e729856009a21a7c3955
BLAKE2b-256 fdf0ee6c52a23e3e171ded06dee284df8f5d0bb72c3e028747262195d031eab2

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_iotevents_actions_alpha-2.163.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_cdk.aws_iotevents_actions_alpha-2.163.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 514c3c0a3bca1413c8bbf57ff1ead8e96055a53c88316555ad7ba190a3f14b37
MD5 f0414b3e459ce663029fc4d915d11bd1
BLAKE2b-256 c242e48f11a8f1e7d5d6fb898f0e058f2ce568c9f0b168e395bc1456b2577d8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page