AWS CloudFormation
User Guide (Version )

AWS::IoTEvents::DetectorModel

The AWS::IoTEvents::DetectorModel resource creates a detector model. You create a detector model (a model of your equipment or process) using states. For each state, you define conditional (Boolean) logic that evaluates the incoming inputs to detect significant events. When an event is detected, it can change the state or trigger custom-built or predefined actions using other AWS services. You can define additional events that trigger actions when entering or exiting a state and, optionally, when a condition is met. For more information, see How to Use AWS IoT Events in the AWS IoT Events Developer Guide.

Note

When you successfully update a detector model (using the AWS IoT Events console, AWS IoT Events API or CLI commands, or AWS CloudFormation) all detector instances created by the model are reset to their initial states. (The detector's state, and the values of any variables and timers are reset.)

When you successfully update a detector model (using the AWS IoT Events console, AWS IoT Events API or CLI commands, or AWS CloudFormation) the version number of the detector model is incremented. (A detector model with version number 1 before the update has version number 2 after the update succeeds.)

If you attempt to update a detector model using AWS CloudFormation and the update does not succeed, the system may, in some cases, restore the original detector model. When this occurs, the detector model's version is incremented twice (for example, from version 1 to version 3) and the detector instances are reset.

Also, be aware that if you attempt to update several detector models at once using AWS CloudFormation, some updates may succeed and others fail. In this case, the effects on each detector model's detector instances and version number depend on whether the update succeeded or failed, with the results as stated.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::IoTEvents::DetectorModel", "Properties" : { "DetectorModelDefinition" : DetectorModelDefinition, "DetectorModelDescription" : String, "DetectorModelName" : String, "Key" : String, "RoleArn" : String, "Tags" : [ Tag, ... ] } }

YAML

Type: AWS::IoTEvents::DetectorModel Properties: DetectorModelDefinition: DetectorModelDefinition DetectorModelDescription: String DetectorModelName: String Key: String RoleArn: String Tags: - Tag

Properties

DetectorModelDefinition

Information that defines how a detector operates.

Required: No

Type: DetectorModelDefinition

Update requires: No interruption

DetectorModelDescription

A brief description of the detector model.

Required: No

Type: String

Maximum: 128

Update requires: No interruption

DetectorModelName

The name of the detector model.

Required: No

Type: String

Minimum: 1

Maximum: 128

Pattern: ^[a-zA-Z0-9_-]+$

Update requires: Replacement

Key

The input attribute key used to identify a device or system to create a detector (an instance of the detector model) and then to route each input received to the appropriate detector (instance). This parameter uses a JSON-path expression to specify the attribute-value pair in the message payload of each input that is used to identify the device associated with the input.

Required: No

Type: String

Minimum: 1

Maximum: 128

Pattern: ^((`[\w\- ]+`)|([\w\-]+))(\.((`[\w- ]+`)|([\w\-]+)))*$

Update requires: Replacement

RoleArn

The ARN of the role that grants permission to AWS IoT Events to perform its operations.

Required: No

Type: String

Minimum: 1

Maximum: 2048

Update requires: No interruption

Tags

An array of key-value pairs to apply to this resource.

For more information, see Tag.

Required: No

Type: List of Tag

Update requires: No interruption

Return Values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the name of the detector model. For example:

{"Ref": "myDetectorModel"}

For the AWS IoT Events detector model myDetectorModel, Ref returns the name of the detector model.

For more information about using the Ref function, see Ref.

Examples

Simple Detector Model

The following example creates a simple detector model with only one state.

JSON

{ "Description": "Simple Detector Model Template", "Resources": { "MyDetectorModel": { "Type": "AWS::IoTEvents::DetectorModel", "Properties": { "DetectorModelName": "myDetectorModel", "DetectorModelDescription": "My Detector Model created by CloudFormation", "Key": "myKey", "RoleArn": { "Fn::GetAtt" : [ "myRole", "Arn" ] }, "DetectorModelDefinition": { "InitialStateName": "myInitialState", "States": [ { "StateName": "myInitialState", "OnInput": { "Events": [ { "EventName": "onInputPublishEvent", "Condition": { "Fn::Join" : [ ".", ["$input", {"Ref": "myInput"}, "foo > 1"] ] }, "Actions": [ { "IotTopicPublish": { "MqttTopic": "myMqttTopic" } } ] } ] } } ] } } } } }

YAML

--- Description: "Simple Detector Model Template" Resources: MyDetectorModel: Type: "AWS::IoTEvents::DetectorModel" Properties: DetectorModelName: "myDetectorModel" DetectorModelDescription: "My Detector Model created by CloudFormation" Key: "myKey" RoleArn: !GetAtt myRole.Arn DetectorModelDefinition: InitialStateName: "myInitialState" States: - StateName: "myInitialState" OnInput: Events: - EventName: "onInputPublishEvent" Condition: !Join [".", ["$input", {'Ref': myInput}, "foo > 1"]] Actions: - IotTopicPublish: MqttTopic: "myMqttTopic"

Full Detector Model

The following example creates a more complete example of a detector model with two states.

JSON

{ "Description": "Detector Model Template for CloudFormation", "Resources": { "MyDetectorModel": { "Type": "AWS::IoTEvents::DetectorModel", "Properties": { "DetectorModelName": "myDetectorModel", "DetectorModelDescription": "My Detector Model created by CloudFormation", "Key": "myKey", "RoleArn": "arn:aws:iam::123456789012:role/myIotEventsRole", "DetectorModelDefinition": { "InitialStateName": "myInitialState", "States": [ { "StateName": "myInitialState", "OnEnter": { "Events": [ { "EventName": "onEnterEvent", "Actions": [ { "SetVariable": { "VariableName": "Variable", "Value": "0" } } ] }, { "EventName": "onEnter Event 2", "Condition": "true", "Actions": [ { "SetTimer": { "TimerName": "myTimer", "Seconds": 60 } } ] } ] }, "OnInput": { "Events": [ { "EventName": "onInputEvent", "Condition": { "Fn::Join" : [ ".", ["$input", {"Ref": "myInput"}, "foo > 1"] ] }, "Actions": [ { "IotTopicPublish": { "MqttTopic": "myMqttTopic" } }, { "ResetTimer": { "TimerName": "myTimer" } } ] } ], "TransitionEvents": [ { "EventName": "Transit to other state", "Condition": "true", "Actions": [ { "Sns": { "TargetArn": "arn:aws:sns:123456789012:mySnsTopic" } }, { "Lambda": { "FunctionArn": "arn:aws:lambda:123456789012:function:myLambdaFunction" } }, { "Firehose": { "DeliveryStreamName": "myStreamName", "Separator": "," } }, { "Sqs": { "QueueUrl": "myQueueUrl", "UseBase64": true } }, { "IotEvents": { "InputName": "myInputName" } } ], "NextState": "myOtherState" } ] }, "OnExit": { "Events": [ { "EventName": "Clear timers", "Condition": "1 == 1", "Actions": [ { "ClearTimer": { "TimerName": "myTimer" } } ] } ] } }, { "StateName": "myOtherState", "OnEnter": { "Events": [ { "EventName": "onEnterEvent", "Actions": [ { "SetVariable": { "VariableName": "Variable", "Value": "0" } } ] }, { "EventName": "onEnter Event 2", "Condition": "true", "Actions": [ { "SetTimer": { "TimerName": "myTimer", "Seconds": 60 } } ] } ] }, "OnExit": { "Events": [ { "EventName": "Clear timers", "Condition": "1 == 1", "Actions": [ { "ClearTimer": { "TimerName": "myTimer" } } ] } ] } } ] } } } } }

YAML

--- Description: "Detector Model Template for CloudFormation" Resources: MyDetectorModel: Type: "AWS::IoTEvents::DetectorModel" Properties: DetectorModelName: "myDetectorModel" DetectorModelDescription: "My Detector Model created by CloudFormation" Key: "myKey" RoleArn: "arn:aws:iam::123456789012:role/myIotEventsRole" DetectorModelDefinition: InitialStateName: "myInitialState" States: - StateName: "myInitialState" OnEnter: Events: - EventName: "onEnterEvent" Actions: - SetVariable: VariableName: "Variable" Value: "0" - EventName: "onEnter Event 2" Condition: "true" Actions: - SetTimer: TimerName: "myTimer" Seconds: 60 OnInput: Events: - EventName: "onInputEvent" Condition: !Join [".", ["$input", {'Ref': myInput}, "foo > 1"]] Actions: - IotTopicPublish: MqttTopic: "myMqttTopic" - ResetTimer: TimerName: "myTimer" TransitionEvents: - EventName: "Transit to other state" Condition: "true" Actions: - Sns: TargetArn: "arn:aws:sns:123456789012:mySnsTopic" - Lambda: FunctionArn: "arn:aws:lambda:123456789012:function:myLambdaFunction" - Firehose: DeliveryStreamName: "myStreamName" Separator: "," - Sqs: QueueUrl: "myQueueUrl" UseBase64: true - IotEvents: InputName: "myInputName" NextState: "myOtherState" OnExit: Events: - EventName: "Clear timers" Condition: "1 == 1" Actions: - ClearTimer: TimerName: "myTimer" - StateName: "myOtherState" OnEnter: Events: - EventName: "onEnterEvent" Actions: - SetVariable: VariableName: "Variable" Value: "0" - EventName: "onEnter Event 2" Condition: "true" Actions: - SetTimer: TimerName: "myTimer" Seconds: 60 OnExit: Events: - EventName: "Clear timers" Condition: "1 == 1" Actions: - ClearTimer: TimerName: "myTimer"

See Also