AWS::IoTEvents::DetectorModel - AWS CloudFormation
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

AWS::IoTEvents::DetectorModel

AWS::IoTEvents::DetectorModel 资源将创建一个探测器模型。您使用状态创建一个探测器模型(您的设备或进程的模型)。对于每种状态,您定义条件(布尔值)逻辑,该逻辑评估传入的输入以检测重要事件。检测到事件后,它可以使用其他 AWS 服务更改状态或触发自定义或预定义的操作。您可以定义其他事件,这些事件将在进入或退出某个状态以及满足某个条件(可选)时触发动作。有关更多信息,请参阅 AWS IoT Events 开发人员指南中的如何使用 AWS IoT Events

注意

当您成功更新探测器模型(使用 AWS IoT Events 控制台、AWS IoT Events API 或 CLI 命令,或者 AWS CloudFormation)后,该模型创建的所有探测器实例将重置为其初始状态。(该探测器的 state,以及任何变量的值和计时器都将重置。)

当您成功更新探测器模型(使用 AWS IoT Events 控制台、AWS IoT Events API 或 CLI 命令,或者 AWS CloudFormation)后,该探测器模型的版本号将递增。(更新之前版本号为 1 的探测器模型在更新成功后的版本号为 2。)

如果您尝试使用 AWS CloudFormation 更新探测器模型,但更新未成功,则在某些情况下,系统可能会还原原来的探测器模型。发生这种情况时,探测器模型的版本将递增两次(例如,从版本 1 递增到版本 3),并重置探测器实例。

另外,请注意,如果您尝试使用 AWS CloudFormation 一次更新多个探测器模型,则有些更新可能会成功,而另一些则会失败。在这种情况下,对每个探测器模型的探测器实例和版本号的影响取决于更新是成功还是失败,其结果如前所述。

语法

要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:

JSON

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

YAML

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

属性

DetectorModelDefinition

定义探测器如何运行的信息。

必需:否

类型DetectorModelDefinition

Update requires: No interruption

DetectorModelDescription

探测器模型的简要说明。

必需:否

类型:字符串

最高128

Update requires: No interruption

DetectorModelName

探测器模型的名称。

必需:否

类型:字符串

最低1

最高128

模式^[a-zA-Z0-9_-]+$

Update requires: Replacement

EvaluationMethod

有关事件的评估顺序以及如何执行操作的信息。

必需:否

类型:字符串

允许的值BATCH | SERIAL

Update requires: No interruption

Key

用于标识检测器实例的值。当设备或系统发送输入时,将创建具有唯一键值的新检测器实例。AWS IoT Events 可以根据此标识信息继续将输入路由到其对应的检测器实例。

此参数使用 JSON 路径表达式在用于标识的消息负载中选择属性值对。要将消息路由到正确的检测器实例,设备必须发送包含相同属性值的消息负载。

必需:否

类型:字符串

最低1

最高128

模式^((`[\w\- ]+`)|([\w\-]+))(\.((`[\w- ]+`)|([\w\-]+)))*$

Update requires: Replacement

RoleArn

角色的 ARN,该角色向 AWS IoT Events 授予权限以执行操作。

必需:否

类型:字符串

最低1

最高2048

Update requires: No interruption

Tags

要应用于此资源的键值对的数组。

有关更多信息,请参阅标签

必需:否

类型Tag 的列表

Update requires: No interruption

返回值

Ref

在将此资源的逻辑 ID 传递给内部 Ref 函数时,Ref 返回 探测器模型的名称。例如:

{"Ref": "myDetectorModel"}

对于 AWS IoT 事件探测器模型 myDetectorModelRef 将返回探测器模型的名称。

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

示例

简单探测器模型

以下示例创建一个简单的探测器模型,只有一个状态。

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"

完整探测器模型

以下示例创建一个更完整的探测器模型,有两种状态。

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"

另请参阅