終止支援通知:2026 年 5 月 20 日, AWS 將終止對 的支援 AWS IoT Events。2026 年 5 月 20 日之後,您將無法再存取 AWS IoT Events 主控台或 AWS IoT Events 資源。如需詳細資訊,請參閱AWS IoT Events 終止支援。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 中擷取 MQTT 訊息 AWS IoT Events
如果您的感應器運算資源無法使用 "BatchPutMessage" API,但可以使用輕量型 MQTT 用戶端將其資料傳送至 AWS IoT Core 訊息代理程式,您可以建立 AWS IoT Core 主題規則,將訊息資料重新導向至 AWS IoT Events 輸入。以下是 AWS IoT Events 主題規則的定義,該規則會採用來自 MQTT 主題的 "areaId"和 "sensorId"輸入欄位,以及來自訊息承載"temp"欄位"sensorData.temperature"的欄位,並將這些資料擷取到我們的 中 AWS IoT Events "temperatureInput"。
CLI 命令:
aws iot create-topic-rule --cli-input-json file://temperatureTopicRule.json
檔案: seedSetDesiredTemp.json
{ "ruleName": "temperatureTopicRule", "topicRulePayload": { "sql": "SELECT topic(3) as areaId, topic(4) as sensorId, temp as sensorData.temperature FROM 'update/temperature/#'", "description": "Ingest temperature sensor messages into IoT Events", "actions": [ { "iotEvents": { "inputName": "temperatureInput", "roleArn": "arn:aws:iam::123456789012:role/service-role/anotheRole" } } ], "ruleDisabled": false, "awsIotSqlVersion": "2016-03-23" } }
回應:【無】
如果感應器傳送有關 主題的訊息,並"update/temperature/Area51/03"包含下列承載。
{ "temp": 24.5 }
這會導致資料被擷取到 中 AWS IoT Events ,就像已進行下列 "BatchPutMessage" API 呼叫一樣。
aws iotevents-data batch-put-message --cli-input-json file://spoofExample.json --cli-binary-format raw-in-base64-out
檔案: spoofExample.json
{ "messages": [ { "messageId": "54321", "inputName": "temperatureInput", "payload": "{\"sensorId\": \"03\", \"areaId\": \"Area51\", \"sensorData\": {\"temperature\": 24.5} }" } ] }