

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 來執行動作和實作常見案例 AWS IoT Events。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `batch-put-message`。

**AWS CLI**  
**傳送訊息 （輸入） 至 AWS IoT 事件**  
下列`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 Analytics 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)。