

# AWS IoT Events examples using AWS CLI
<a name="cli_iot-events_code_examples"></a>

次のコード例では、AWS IoT Events で AWS Command Line Interface を使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。

**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`) に変換され、その入力をモニタリングするディテクターに取り込まれます。複数のメッセージが送信された場合、メッセージが処理される順序は保証されません。順序を保証するには、メッセージを一度に 1 つずつ送信し、成功のレスポンスを待つ必要があります。  

```
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` の例では、指定されたディテクターモデルの 1 つ以上のディテクター (インスタンス) の状態、変数値、タイマー設定を更新します。  

```
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` のいずれかのフィールドの値を更新する場合 (無効なポリシーを修正するなど)、その変更が有効になるまでに最大 5 分かかることがあります。  

```
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)」を参照してください。