

# 使用 AWS CLI 的 AWS IoT Events示例
<a name="cli_iot-events_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 AWS IoT Events 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `batch-put-message`
<a name="iot-events_BatchPutMessage_cli_topic"></a>

以下代码示例演示了如何使用 `batch-put-message`。

**AWS CLI**  
**向 AWS IoT Events 发送消息（输入）**  
以下 `batch-put-message` 示例向 AWS IoT Events 系统发送一组消息。每个消息有效载荷都将转换为您指定的输入 (`inputName`)，并提取到任何监视该输入的检测器中。如果发送多条消息，不能保证按顺序处理消息。为确保按序处理，您必须一次发送一条消息，等收到成功回应后，再发送下一条。  

```
aws iotevents-data batch-put-message \
    --cli-input-json file://highPressureMessage.json
```
 的内容`highPressureMessage.json`：  

```
{
    "messages": [
        {
            "messageId": "00001",
            "inputName": "PressureInput",
            "payload": "{\"motorid\": \"Fulton-A32\", \"sensorData\": {\"pressure\": 80, \"temperature\": 39} }"
        }
    ]
}
```
输出：  

```
{
    "BatchPutMessageErrorEntries": []
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [BatchPutMessage](https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchPutMessage](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/batch-put-message.html)。

### `batch-update-detector`
<a name="iot-events_BatchUpdateDetector_cli_topic"></a>

以下代码示例演示了如何使用 `batch-update-detector`。

**AWS CLI**  
**更新检测器（实例）**  
以下 `batch-update-detector` 示例更新指定检测器模型的一个或多个检测器（实例）的状态、变量值和计时器设置。  

```
aws iotevents-data batch-update-detector \
    --cli-input-json file://budFulton-A32.json
```
 的内容`budFulton-A32.json`：  

```
{
    "detectors": [
        {
            "messageId": "00001",
            "detectorModelName": "motorDetectorModel",
            "keyValue": "Fulton-A32",
            "state": {
                "stateName": "Normal",
                "variables": [
                    {
                        "name": "pressureThresholdBreached",
                        "value": "0"
                    }
                ],
                "timers": [
                ]
            }
        }
    ]
}
```
输出：  

```
{
    "batchUpdateDetectorErrorEntries": []
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [BatchUpdateDetector](https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchUpdateDetector.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchUpdateDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/batch-update-detector.html)。

### `create-detector-model`
<a name="iot-events_CreateDetectorModel_cli_topic"></a>

以下代码示例演示了如何使用 `create-detector-model`。

**AWS CLI**  
**创建检测器模型**  
以下 `create-detector-model` 示例创建了一个检测器模型，其配置由参数文件指定。  

```
aws iotevents create-detector-model  \
    --cli-input-json file://motorDetectorModel.json
```
 的内容`motorDetectorModel.json`：  

```
{
    "detectorModelName": "motorDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Normal",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "Overpressurized",
                            "condition": "$input.PressureInput.sensorData.pressure &gt; 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "$variable.pressureThresholdBreached + 3"
                                    }
                                }
                            ],
                            "nextState": "Dangerous"
                        }
                    ]
                }
            },
            {
                "stateName": "Dangerous",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Pressure Threshold Breached",
                            "condition": "$variable.pressureThresholdBreached &gt; 1",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:underPressureAction"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overpressurized",
                            "condition": "$input.PressureInput.sensorData.pressure &gt; 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "3"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Pressure Okay",
                            "condition": "$input.PressureInput.sensorData.pressure &lt;= 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "$variable.pressureThresholdBreached - 1"
                                    }
                                }
                            ]
                        }
                    ],
                    "transitionEvents": [
                        {
                            "eventName": "BackToNormal",
                            "condition": "$input.PressureInput.sensorData.pressure &lt;= 70 &amp;&amp; $variable.pressureThresholdBreached &lt;= 1",
                            "nextState": "Normal"
                        }
                    ]
                },
                "onExit": {
                    "events": [
                        {
                            "eventName": "Normal Pressure Restored",
                            "condition": "true",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:pressureClearedAction"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Normal"
    },
    "key": "motorid",
    "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole"
}
```
输出：  

```
{
    "detectorModelConfiguration": {
        "status": "ACTIVATING",
        "lastUpdateTime": 1560796816.077,
        "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
        "creationTime": 1560796816.077,
        "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/motorDetectorModel",
        "key": "motorid",
        "detectorModelName": "motorDetectorModel",
        "detectorModelVersion": "1"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [CreateDetectorModel](https://docs.aws.amazon.com/iotevents/latest/apireference/API_CreateDetectorModel.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/create-detector-model.html)。

### `create-input`
<a name="iot-events_CreateInput_cli_topic"></a>

以下代码示例演示了如何使用 `create-input`。

**AWS CLI**  
**创建输入**  
以下 `create-input` 示例创建了一个输入。  

```
aws iotevents create-input  \
    --cli-input-json file://pressureInput.json
```
 的内容`pressureInput.json`：  

```
{
    "inputName": "PressureInput",
    "inputDescription": "Pressure readings from a motor",
    "inputDefinition": {
        "attributes": [
            { "jsonPath": "sensorData.pressure" },
            { "jsonPath": "motorid" }
        ]
    }
}
```
输出：  

```
{
    "inputConfiguration": {
        "status": "ACTIVE",
        "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
        "lastUpdateTime": 1560795312.542,
        "creationTime": 1560795312.542,
        "inputName": "PressureInput",
        "inputDescription": "Pressure readings from a motor"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [CreateInput](https://docs.aws.amazon.com/iotevents/latest/apireference/API_CreateInput)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [CreateInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/create-input.html)**。

### `delete-detector-model`
<a name="iot-events_DeleteDetectorModel_cli_topic"></a>

以下代码示例演示了如何使用 `delete-detector-model`。

**AWS CLI**  
**删除检测器模型**  
以下 `delete-detector-model` 示例删除了指定的检测器模型。该检测器模型的所有活动实例也被删除。  

```
aws iotevents delete-detector-model \
    --detector-model-name motorDetectorModel
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DeleteDetectorModel](https://docs.aws.amazon.com/iotevents/latest/apireference/API_DeleteDetectorModel)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/delete-detector-model.html)。

### `delete-input`
<a name="iot-events_DeleteInput_cli_topic"></a>

以下代码示例演示了如何使用 `delete-input`。

**AWS CLI**  
**删除输入**  
以下 `delete-input` 示例删除了指定输入。  

```
aws iotevents delete-input \
    --input-name PressureInput
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DeleteInput](https://docs.aws.amazon.com/iotevents/latest/apireference/API_DeleteInput)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [DeleteInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/delete-input.html)**。

### `describe-detector-model`
<a name="iot-events_DescribeDetectorModel_cli_topic"></a>

以下代码示例演示了如何使用 `describe-detector-model`。

**AWS CLI**  
**获取有关检测器模型的信息**  
以下 `describe-detector-model` 示例显示指定检测器模型的详细信息。由于未指定 `version` 参数，所以返回的是有关最新版本的信息。  

```
aws iotevents describe-detector-model \
    --detector-model-name motorDetectorModel
```
输出：  

```
{
    "detectorModel": {
        "detectorModelConfiguration": {
            "status": "ACTIVE",
            "lastUpdateTime": 1560796816.077,
            "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
            "creationTime": 1560796816.077,
            "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/motorDetectorModel",
            "key": "motorid",
            "detectorModelName": "motorDetectorModel",
            "detectorModelVersion": "1"
        },
        "detectorModelDefinition": {
            "states": [
                {
                    "onInput": {
                        "transitionEvents": [
                            {
                                "eventName": "Overpressurized",
                                "actions": [
                                    {
                                        "setVariable": {
                                            "variableName": "pressureThresholdBreached",
                                            "value": "$variable.pressureThresholdBreached + 3"
                                        }
                                    }
                                ],
                                "condition": "$input.PressureInput.sensorData.pressure > 70",
                                "nextState": "Dangerous"
                            }
                        ],
                        "events": []
                    },
                    "stateName": "Normal",
                    "onEnter": {
                        "events": [
                            {
                                "eventName": "init",
                                "actions": [
                                    {
                                        "setVariable": {
                                            "variableName": "pressureThresholdBreached",
                                            "value": "0"
                                        }
                                    }
                                ],
                                "condition": "true"
                            }
                        ]
                    },
                    "onExit": {
                        "events": []
                    }
                },
                {
                    "onInput": {
                        "transitionEvents": [
                            {
                                "eventName": "BackToNormal",
                                "actions": [],
                                "condition": "$input.PressureInput.sensorData.pressure <= 70 && $variable.pressureThresholdBreached <= 1",
                                "nextState": "Normal"
                            }
                        ],
                        "events": [
                            {
                                "eventName": "Overpressurized",
                                "actions": [
                                    {
                                        "setVariable": {
                                            "variableName": "pressureThresholdBreached",
                                            "value": "3"
                                        }
                                    }
                                ],
                                "condition": "$input.PressureInput.sensorData.pressure > 70"
                            },
                            {
                                "eventName": "Pressure Okay",
                                "actions": [
                                    {
                                        "setVariable": {
                                            "variableName": "pressureThresholdBreached",
                                            "value": "$variable.pressureThresholdBreached - 1"
                                        }
                                    }
                                ],
                                "condition": "$input.PressureInput.sensorData.pressure <= 70"
                            }
                        ]
                    },
                    "stateName": "Dangerous",
                    "onEnter": {
                        "events": [
                            {
                                "eventName": "Pressure Threshold Breached",
                                "actions": [
                                    {
                                        "sns": {
                                            "targetArn": "arn:aws:sns:us-east-1:123456789012:underPressureAction"
                                        }
                                    }
                                ],
                                "condition": "$variable.pressureThresholdBreached > 1"
                            }
                        ]
                    },
                    "onExit": {
                        "events": [
                            {
                                "eventName": "Normal Pressure Restored",
                                "actions": [
                                    {
                                        "sns": {
                                            "targetArn": "arn:aws:sns:us-east-1:123456789012:pressureClearedAction"
                                        }
                                    }
                                ],
                                "condition": "true"
                            }
                        ]
                    }
                }
            ],
            "initialStateName": "Normal"
        }
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DescribeDetectorModel](https://docs.aws.amazon.com/iotevents/latest/apireference/API_DescribeDetectorModel)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/describe-detector-model.html)。

### `describe-detector`
<a name="iot-events_DescribeDetector_cli_topic"></a>

以下代码示例演示了如何使用 `describe-detector`。

**AWS CLI**  
**获取有关检测器（实例）的信息**  
以下 `describe-detector` 示例显示指定检测器（实例）的详细信息。  

```
aws iotevents-data describe-detector \
    --detector-model-name motorDetectorModel \
    --key-value "Fulton-A32"
```
输出：  

```
{
    "detector": {
        "lastUpdateTime": 1560797852.776,
        "creationTime": 1560797852.775,
        "state": {
            "variables": [
                {
                    "name": "pressureThresholdBreached",
                    "value": "3"
                }
            ],
            "stateName": "Dangerous",
            "timers": []
        },
        "keyValue": "Fulton-A32",
        "detectorModelName": "motorDetectorModel",
        "detectorModelVersion": "1"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DescribeDetector](https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_DescribeDetector)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/describe-detector.html)。

### `describe-input`
<a name="iot-events_DescribeInput_cli_topic"></a>

以下代码示例演示了如何使用 `describe-input`。

**AWS CLI**  
**获取有关输入的信息**  
以下 `describe-input` 示例显示指定输入的详细信息。  

```
aws iotevents describe-input \
    --input-name PressureInput
```
输出：  

```
{
    "input": {
        "inputConfiguration": {
            "status": "ACTIVE",
            "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
            "lastUpdateTime": 1560795312.542,
            "creationTime": 1560795312.542,
            "inputName": "PressureInput",
            "inputDescription": "Pressure readings from a motor"
        },
        "inputDefinition": {
            "attributes": [
                {
                    "jsonPath": "sensorData.pressure"
                },
                {
                    "jsonPath": "motorid"
                }
            ]
        }
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DescribeInput](https://docs.aws.amazon.com/iotevents/latest/apireference/API_DescribeInput)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/describe-input.html)。

### `describe-logging-options`
<a name="iot-events_DescribeLoggingOptions_cli_topic"></a>

以下代码示例演示了如何使用 `describe-logging-options`。

**AWS CLI**  
**获取有关日志设置的信息**  
以下 `describe-logging-options` 示例检索 AWS IoT Events 日志记录选项的当前设置。  

```
aws iotevents describe-logging-options
```
输出：  

```
{
    "loggingOptions": {
        "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
        "enabled": false,
        "level": "ERROR"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [DescribeLoggingOptions](https://docs.aws.amazon.com/iotevents/latest/apireference/API_DescribeLoggingOptions)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DescribeLoggingOptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/describe-logging-options.html)。

### `list-detector-model-versions`
<a name="iot-events_ListDetectorModelVersions_cli_topic"></a>

以下代码示例演示了如何使用 `list-detector-model-versions`。

**AWS CLI**  
**获取有关检测器模型版本的信息**  
以下 `list-detector-model-versions` 示例列出某个检测器模型的所有版本。仅返回与每个检测器模型版本关联的元数据。  

```
aws iotevents list-detector-model-versions \
    --detector-model-name motorDetectorModel
```
输出：  

```
{
    "detectorModelVersionSummaries": [
        {
            "status": "ACTIVE",
            "lastUpdateTime": 1560796816.077,
            "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
            "creationTime": 1560796816.077,
            "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/motorDetectorModel",
            "detectorModelName": "motorDetectorModel",
            "detectorModelVersion": "1"
        }
    ]
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [ListDetectorModelVersions](https://docs.aws.amazon.com/iotevents/latest/apireference/API_ListDetectorModelVersions)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListDetectorModelVersions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/list-detector-model-versions.html)。

### `list-detector-models`
<a name="iot-events_ListDetectorModels_cli_topic"></a>

以下代码示例演示了如何使用 `list-detector-models`。

**AWS CLI**  
**获取您的检测器模型列表**  
以下 `list-detector-models` 示例列出您创建的检测器模型。仅返回与每个检测器模型关联的元数据。  

```
aws iotevents list-detector-models
```
输出：  

```
{
    "detectorModelSummaries": [
        {
            "detectorModelName": "motorDetectorModel",
            "creationTime": 1552072424.212
            "detectorModelDescription": "Detect overpressure in a motor."
        }
    ]
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [ListDetectorModels](https://docs.aws.amazon.com/iotevents/latest/apireference/API_ListDetectorModels)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [ListDetectorModels](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/list-detector-models.html)**。

### `list-detectors`
<a name="iot-events_ListDetectors_cli_topic"></a>

以下代码示例演示了如何使用 `list-detectors`。

**AWS CLI**  
**获取检测器模型的检测器列表**  
以下 `list-detectors` 示例列出了您的账户中的检测器（检测器模型的实例）。  

```
aws iotevents-data list-detectors \
    --detector-model-name motorDetectorModel
```
输出：  

```
{
    "detectorSummaries": [
        {
            "lastUpdateTime": 1558129925.2,
            "creationTime": 1552073155.527,
            "state": {
                "stateName": "Normal"
            },
            "keyValue": "Fulton-A32",
            "detectorModelName": "motorDetectorModel",
            "detectorModelVersion": "1"
        }
    ]
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [ListDetectors](https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_ListDetectors)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListDetectors](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/list-detectors.html)。

### `list-inputs`
<a name="iot-events_ListInputs_cli_topic"></a>

以下代码示例演示了如何使用 `list-inputs`。

**AWS CLI**  
**列出输入**  
以下 `list-inputs` 示例列出您在自己的账户中创建的输入。  

```
aws iotevents list-inputs
```
此命令不生成任何输出。输出：  

```
{
    {
        "status": "ACTIVE",
        "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
        "lastUpdateTime": 1551742986.768,
        "creationTime": 1551742986.768,
        "inputName": "PressureInput",
        "inputDescription": "Pressure readings from a motor"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [ListInputs](https://docs.aws.amazon.com/iotevents/latest/apireference/API_ListInputs)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [ListInputs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/list-inputs.html)**。

### `list-tags-for-resource`
<a name="iot-events_ListTagsForResource_cli_topic"></a>

以下代码示例演示了如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出分配给资源的标签**  
以下 `list-tags-for-resource` 示例列出您分配给资源的标签键名称和值。  

```
aws iotevents list-tags-for-resource \
    --resource-arn "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput"
```
输出：  

```
{
    "tags": [
        {
            "value": "motor",
            "key": "deviceType"
        }
    ]
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [ListTagsForResource](https://docs.aws.amazon.com/iotevents/latest/apireference/API_ListTagsForResource)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/list-tags-for-resource.html)。

### `put-logging-options`
<a name="iot-events_PutLoggingOptions_cli_topic"></a>

以下代码示例演示了如何使用 `put-logging-options`。

**AWS CLI**  
**设置日志选项**  
以下 `put-logging-options` 示例设置或更新 AWS IoT Events 日志选项。如果您更新了任何 `loggingOptions` field, it can take up to one minute for the change to take effect. Also, if you change the policy attached to the role you specified in the ``roleArn` 字段的值（例如，更正无效策略），则最多需要五分钟，更改就能生效。  

```
aws iotevents put-logging-options \
    --cli-input-json file://logging-options.json
```
 的内容`logging-options.json`：  

```
{
    "loggingOptions": {
        "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
        "level": "DEBUG",
        "enabled": true,
        "detectorDebugOptions": [
            {
                "detectorModelName": "motorDetectorModel",
                "keyValue": "Fulton-A32"
            }
        ]
    }
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [PutLoggingOptions](https://docs.aws.amazon.com/iotevents/latest/apireference/API_PutLoggingOptions)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [PutLoggingOptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/put-logging-options.html)。

### `tag-resource`
<a name="iot-events_TagResource_cli_topic"></a>

以下代码示例演示了如何使用 `tag-resource`。

**AWS CLI**  
**为资源添加标签**  
以下 `tag-resource` 示例添加或修改（如果键 `deviceType` 已存在）附加到指定资源的标签。  

```
aws iotevents tag-resource \
    --cli-input-json file://pressureInput.tag.json
```
 的内容`pressureInput.tag.json`：  

```
{
    "resourceArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
    "tags": [
        {
            "key": "deviceType",
            "value": "motor"
        }
    ]
}
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [TagResource](https://docs.aws.amazon.com/iotevents/latest/apireference/API_TagResource)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/tag-resource.html)。

### `untag-resource`
<a name="iot-events_UntagResource_cli_topic"></a>

以下代码示例演示了如何使用 `untag-resource`。

**AWS CLI**  
**从资源中删除标签**  
以下 `untag-resource` 示例从指定资源中移除具有指定键名的标签。  

```
aws iotevents untag-resource \
    --resource-arn arn:aws:iotevents:us-west-2:123456789012:input/PressureInput \
    --tagkeys deviceType
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [UntagResource](https://docs.aws.amazon.com/iotevents/latest/apireference/API_UntagResource)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/untag-resource.html)。

### `update-detector-model`
<a name="iot-events_UpdateDetectorModel_cli_topic"></a>

以下代码示例演示了如何使用 `update-detector-model`。

**AWS CLI**  
**更新检测器模型**  
以下 `update-detector-model` 示例更新了指定的检测器模型。先前版本生成的检测器（实例）会被删除，然后在新输入到来时重新创建。  

```
aws iotevents update-detector-model \
    --cli-input-json file://motorDetectorModel.update.json
```
 的内容`motorDetectorModel.update.json`：  

```
{
    "detectorModelName": "motorDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Normal",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "Overpressurized",
                            "condition": "$input.PressureInput.sensorData.pressure > 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "$variable.pressureThresholdBreached + 3"
                                    }
                                }
                            ],
                            "nextState": "Dangerous"
                        }
                    ]
                }
            },
            {
                "stateName": "Dangerous",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Pressure Threshold Breached",
                            "condition": "$variable.pressureThresholdBreached > 1",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:underPressureAction"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overpressurized",
                            "condition": "$input.PressureInput.sensorData.pressure > 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "3"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Pressure Okay",
                            "condition": "$input.PressureInput.sensorData.pressure <= 70",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "pressureThresholdBreached",
                                        "value": "$variable.pressureThresholdBreached - 1"
                                    }
                                }
                            ]
                        }
                    ],
                    "transitionEvents": [
                        {
                            "eventName": "BackToNormal",
                            "condition": "$input.PressureInput.sensorData.pressure <= 70 && $variable.pressureThresholdBreached <= 1",
                            "nextState": "Normal"
                        }
                    ]
                },
                "onExit": {
                    "events": [
                        {
                            "eventName": "Normal Pressure Restored",
                            "condition": "true",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:pressureClearedAction"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Normal"
    },
    "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole"
}
```
输出：  

```
{
    "detectorModelConfiguration": {
        "status": "ACTIVATING",
        "lastUpdateTime": 1560799387.719,
        "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole",
        "creationTime": 1560799387.719,
        "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/motorDetectorModel",
        "key": "motorid",
        "detectorModelName": "motorDetectorModel",
        "detectorModelVersion": "2"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [UpdateDetectorModel](https://docs.aws.amazon.com/iotevents/latest/apireference/API_UpdateDetectorModel)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/update-detector-model.html)。

### `update-input`
<a name="iot-events_UpdateInput_cli_topic"></a>

以下代码示例演示了如何使用 `update-input`。

**AWS CLI**  
**更新输入**  
以下 `update-input` 示例使用新的描述和定义更新了指定的输入。  

```
aws iotevents update-input \
    --cli-input-json file://pressureInput.json
```
 的内容`pressureInput.json`：  

```
{
    "inputName": "PressureInput",
    "inputDescription": "Pressure readings from a motor",
    "inputDefinition": {
        "attributes": [
            { "jsonPath": "sensorData.pressure" },
            { "jsonPath": "motorid" }
        ]
    }
}
```
输出：  

```
{
    "inputConfiguration": {
        "status": "ACTIVE",
        "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
        "lastUpdateTime": 1560795976.458,
        "creationTime": 1560795312.542,
        "inputName": "PressureInput",
        "inputDescription": "Pressure readings from a motor"
    }
}
```
有关更多信息，请参阅《AWS IoT Events API 参考》**中的 [UpdateInput](https://docs.aws.amazon.com/iotevents/latest/apireference/API_UpdateInput)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [UpdateInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents/update-input.html)**。