分析检测程序模型 (Amazon CLI) - Amazon IoT Events
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

分析检测程序模型 (Amazon CLI)

以下步骤使用 Amazon CLI 来分析检测程序模型。

  1. 运行以下命令以启动分析。

    aws iotevents start-detector-model-analysis --cli-input-json file://file-name.json
    注意

    file-name替换为包含检测程序模型定义的文件名称。

    例 检测程序模型定义
    { "detectorModelDefinition": { "states": [ { "stateName": "TemperatureCheck", "onInput": { "events": [ { "eventName": "Temperature Received", "condition": "isNull($input.TemperatureInput.sensorData.temperature)==false", "actions": [ { "iotTopicPublish": { "mqttTopic": "IoTEvents/Output" } } ] } ], "transitionEvents": [] }, "onEnter": { "events": [ { "eventName": "Init", "condition": "true", "actions": [ { "setVariable": { "variableName": "temperatureChecked", "value": "0" } } ] } ] }, "onExit": { "events": [] } } ], "initialStateName": "TemperatureCheck" } }

    如果您使用Amazon CLI分析现有检测程序模型,从以下选择一项,以检索检测程序模型定义:

    • 要使用 Amazon IoT Events 控制台,请执行以下操作:

      1. 在导航窗格中,选择检测程序模型

      2. 检测程序模型下,选择目标检测程序模型。

      3. 操作中选择导出检测程序模型以下载检测程序模型。此检测程序模型以 JSON 格式保存。

      4. 打开检测程序模型 JSON 文件。

      5. 您只需要 detectorModelDefinition 对象。移除以下内容:

        • 页面顶部的第一个大括号 ({)

        • detectorModel 线

        • detectorModelConfiguration 对象

        • 页面底部的最后一个大括号(}

      6. 保存该文件。

    • 如果您想要使用 Amazon CLI,请执行以下操作:

      1. 在终端中运行以下命令。

        aws iotevents describe-detector-model --detector-model-name detector-model-name
      2. detector-model-name替换为检测程序模型名称。

      3. detectorModelDefinition对象复制至文本编辑器。

      4. detectorModelDefinition外面添加大括号 ({})。

      5. 以 JSON 格式保存此文件。

    例 响应示例
    { "analysisId": "c1133390-14e3-4204-9a66-31efd92a4fed" }
  2. 从输出项中复制分析 ID。

  3. 运行以下命令,以检索分析状态。

    aws iotevents describe-detector-model-analysis --analysis-id "analysis-id"
    注意

    analysis-id替换为您复制的分析 ID。

    例 响应示例
    { "status": "COMPLETE" }

    状态可以是以下值之一:

    • RUNNING – Amazon IoT Events 正在分析您的检测程序模型。完成此过程可能最多需要一分钟。

    • COMPLETE – Amazon IoT Events 已完成检测程序模型分析。

    • FAILED – Amazon IoT Events 无法分析检测程序模型。请稍后重试。

  4. 运行以下命令,以检索一个或多个检测程序模型分析结果。

    注意

    analysis-id替换为您复制的分析 ID。

    aws iotevents get-detector-model-analysis-results --analysis-id "analysis-id"
    例 响应示例
    { "analysisResults": [ { "type": "data-type", "level": "INFO", "message": "Inferred data types [Integer] for $variable.temperatureChecked", "locations": [] }, { "type": "referenced-resource", "level": "ERROR", "message": "Detector Model Definition contains reference to Input 'TemperatureInput' that does not exist.", "locations": [ { "path": "states[0].onInput.events[0]" } ] } ] }
注意

Amazon IoT Events 开始分析您的检测程序模型后,您最多有 24 小时来检索分析结果。