Package software.amazon.awscdk.services.iotevents


@Stability(Experimental) @Deprecated package software.amazon.awscdk.services.iotevents
Deprecated.

AWS::IoTEvents Construct Library

---

End-of-Support

AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2.

For more information on how to migrate, see the Migrating to AWS CDK v2 guide.


AWS IoT Events enables you to monitor your equipment or device fleets for failures or changes in operation, and to trigger actions when such events occur.

Installation

Install the module:

 $ npm i @aws-cdk/aws-iotevents
 

Import it into your code:

 import software.amazon.awscdk.services.iotevents.*;
 

DetectorModel

The following example creates an AWS IoT Events detector model to your stack. The detector model need a reference to at least one AWS IoT Events input. AWS IoT Events inputs enable the detector to get MQTT payload values from IoT Core rules.

You can define built-in actions to use a timer or set a variable, or send data to other AWS resources. See also @aws-cdk/aws-iotevents-actions for other actions.

 import software.amazon.awscdk.services.iotevents.*;
 import software.amazon.awscdk.services.iotevents.actions.*;
 import software.amazon.awscdk.services.lambda.*;
 
 IFunction func;
 
 
 Input input = Input.Builder.create(this, "MyInput")
         .inputName("my_input") // optional
         .attributeJsonPaths(List.of("payload.deviceId", "payload.temperature"))
         .build();
 
 State warmState = State.Builder.create()
         .stateName("warm")
         .onEnter(List.of(Event.builder()
                 .eventName("test-enter-event")
                 .condition(Expression.currentInput(input))
                 .actions(List.of(new LambdaInvokeAction(func)))
                 .build()))
         .onInput(List.of(Event.builder() // optional
                 .eventName("test-input-event")
                 .actions(List.of(new LambdaInvokeAction(func))).build()))
         .onExit(List.of(Event.builder() // optional
                 .eventName("test-exit-event")
                 .actions(List.of(new LambdaInvokeAction(func))).build()))
         .build();
 State coldState = State.Builder.create()
         .stateName("cold")
         .build();
 
 // transit to coldState when temperature is less than 15
 warmState.transitionTo(coldState, TransitionOptions.builder()
         .eventName("to_coldState") // optional property, default by combining the names of the States
         .when(Expression.lt(Expression.inputAttribute(input, "payload.temperature"), Expression.fromString("15")))
         .executing(List.of(new LambdaInvokeAction(func)))
         .build());
 // transit to warmState when temperature is greater than or equal to 15
 coldState.transitionTo(warmState, TransitionOptions.builder()
         .when(Expression.gte(Expression.inputAttribute(input, "payload.temperature"), Expression.fromString("15")))
         .build());
 
 DetectorModel.Builder.create(this, "MyDetectorModel")
         .detectorModelName("test-detector-model") // optional
         .description("test-detector-model-description") // optional property, default is none
         .evaluationMethod(EventEvaluation.SERIAL) // optional property, default is iotevents.EventEvaluation.BATCH
         .detectorKey("payload.deviceId") // optional property, default is none and single detector instance will be created and all inputs will be routed to it
         .initialState(warmState)
         .build();
 

To grant permissions to put messages in the input, you can use the grantWrite() method:

 import software.amazon.awscdk.services.iam.*;
 import software.amazon.awscdk.services.iotevents.*;
 
 IGrantable grantable;
 
 IInput input = Input.fromInputName(this, "MyInput", "my_input");
 
 input.grantWrite(grantable);
 
Deprecated: AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2. For more information on how to migrate, see https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html