本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Amazon IoT Events
Amazon IoT Events (iotEvents
) 操作将数据从 MQTT 消息发送到 Amazon IoT Events 输入。
重要
如果将有效负载发送到时 Amazon IoT Core 不带有Input attribute Key
,或者密钥不在密钥中指定的 JSON 路径中,则会导致物联网规则失败并出现错误Failed to send message to Iot Events
。
要求
此规则操作具有以下要求:
-
Amazon IoT 可以代入执行
iotevents:BatchPutMessage
操作的 IAM 角色。有关更多信息,请参阅 授予 Amazon IoT 规则所需的访问权限。在 Amazon IoT 控制台中,您可以选择或创建 Amazon IoT 允许执行此规则操作的角色。
参数
使用此操作创建 Amazon IoT 规则时,必须指定以下信息:
batchMode
-
(可选)是否批处理事件操作。默认值为
false
。如果
batchMode
为true
且规则 SQL 语句的求值为一个 Array 时,通过调用BatchPutMessage
将 Array 元素发送到 Amazon IoT Events 时,会将每个 Array 元素都视为单独的消息。生成的数组,其消息不得超过 10 条。batchMode
为true
时,不能指定messageId
。支持替换模板:否
inputName
-
Amazon IoT Events 输入的名称。
支持替换模板:API 且 Amazon CLI 仅支持
messageId
-
(可选)使用它来验证 Amazon IoT Events 检测器
messageId
是否只处理一个给定输入(消息)。您可以使用${newuuid()}
替代模板,以便为每个请求生成一个唯一的 ID。当
batchMode
为true
时,您无法指定messageId
-- 将分配一个新 UUID 值。支持替换模板:是
roleArn
-
允许 Amazon IoT 向 Amazon IoT Events 检测器发送输入的 IAM 角色。有关更多信息,请参阅 要求。
支持替换模板:否
示例
下面的 JSON 示例介绍了如何在 Amazon IoT 规则中定义 IoT Events 操作。
{ "topicRulePayload": { "sql": "SELECT * FROM 'some/topic", "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23", "actions": [ { "iotEvents": { "inputName": "MyIoTEventsInput", "messageId": "${newuuid()}", "roleArn": "arn:aws:iam::123456789012:role/aws_iot_events" } } ] } }
另请参阅
-
什么是 Amazon IoT Events? 在《Amazon IoT Events 开发者指南》中