DetectorModel
The DetectorModel resource allows you to manage AWS IoTEvents DetectorModels for monitoring events from IoT devices and triggering actions based on defined conditions.
Minimal Example
Section titled “Minimal Example”Create a basic DetectorModel with required properties and one optional property:
import AWS from "alchemy/aws/control";
const basicDetectorModel = await AWS.IoTEvents.DetectorModel("basicDetectorModel", { DetectorModelDefinition: { InitialStateName: "initialState", States: [ { StateName: "initialState", OnEnter: { Events: [ { EventName: "event1", Condition: "true", Actions: [ { SetVariable: { VariableName: "variable1", Value: "value1" } } ] } ] } } ] }, RoleArn: "arn:aws:iam::123456789012:role/service-role/iot-events-role", EvaluationMethod: "BATCH"});
Advanced Configuration
Section titled “Advanced Configuration”Configure a DetectorModel with additional properties like description and tags for better management:
const advancedDetectorModel = await AWS.IoTEvents.DetectorModel("advancedDetectorModel", { DetectorModelDefinition: { InitialStateName: "advancedState", States: [ { StateName: "advancedState", OnEnter: { Events: [ { EventName: "event2", Condition: "temperature > 30", Actions: [ { SetVariable: { VariableName: "status", Value: "overheating" } }, { TriggerNotification: { NotificationArn: "arn:aws:sns:us-east-1:123456789012:myTopic" } } ] } ] } } ] }, DetectorModelName: "AdvancedDetectorModel", DetectorModelDescription: "A detector model to monitor temperature.", RoleArn: "arn:aws:iam::123456789012:role/service-role/iot-events-role", Tags: [ { Key: "Environment", Value: "Production" } ]});
Custom Evaluation Method
Section titled “Custom Evaluation Method”Create a DetectorModel that uses a custom evaluation method:
const customEvaluationDetectorModel = await AWS.IoTEvents.DetectorModel("customEvalDetectorModel", { DetectorModelDefinition: { InitialStateName: "customState", States: [ { StateName: "customState", OnEnter: { Events: [ { EventName: "event3", Condition: "humidity < 40", Actions: [ { SetVariable: { VariableName: "humidityStatus", Value: "low" } } ] } ] } } ] }, RoleArn: "arn:aws:iam::123456789012:role/service-role/iot-events-role", EvaluationMethod: "SERIAL"});