Package: aws-cdk.aws-iotevents-actions-alpha
Actions for AWS::IoTEvents Detector Model---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 theSemantic Versioningmodel 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 toStatedefined in@aws-cdk/aws-iotevents-alphaYou 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 timerSet variable to detector instanceInvoke a Lambda functionUse timerThe code snippet below creates an Action that creates the timer with duration in seconds.# Example automatically generated from non-compiling source. May contain errors.importaws_cdk.aws_iotevents_alphaasioteventsimportaws_cdk.aws_iotevents_actions_alphaasactions# input: iotevents.IInputstate=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 byIoT 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 generalDevice HeartBeatDetector 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 instanceThe code snippet below creates an Action that set variable to detector instance
when it is triggered.importaws_cdk.aws_iotevents_alphaasioteventsimportaws_cdk.aws_iotevents_actions_alphaasactions# input: iotevents.IInputstate=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 functionThe code snippet below creates an Action that invoke a Lambda function
when it is triggered.importaws_cdk.aws_iotevents_alphaasioteventsimportaws_cdk.aws_iotevents_actions_alphaasactionsimportaws_cdk.aws_lambdaaslambda_# input: iotevents.IInput# func: lambda.IFunctionstate=iotevents.State(state_name="MyState",on_enter=[iotevents.Event(event_name="test-event",condition=iotevents.Expression.current_input(input),actions=[actions.LambdaInvokeAction(func)])])