

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

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

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

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

**Topics**
+ [アクション](#actions)

## アクション
<a name="actions"></a>

### `batch-put-message`
<a name="iot-events-data_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-binary-format raw-in-base64-out \
    --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 デベロッパーガイド\$1*」の「[BatchPutMessage](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-data-BatchPutMessage)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[BatchPutMessage](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/batch-put-message.html)」を参照してください。

### `batch-update-detector`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[BatchUpdateDetector](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-data-BatchUpdateDetector)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[BatchUpdateDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/batch-update-detector.html)」を参照してください。

### `create-detector-model`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[CreateDetectorModel](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-CreateDetectorModel)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[CreateDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/create-detector-model.html)」を参照してください。

### `create-input`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[CreateInput](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-CreateInput)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[CreateInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/create-input.html)」を参照してください。

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

次のコード例は、`delete-detector-model` を使用する方法を示しています。

**AWS CLI**  
**ディテクターモデルを削除するには**  
次の `delete-detector-model` の例では、ディテクターモデルを削除します。ディテクターモデルのアクティブなインスタンスも削除されます。  

```
aws iotevents delete-detector-model \
    --detector-model-name motorDetectorModel*
```
このコマンドでは何も出力されません。  
詳細については、「*AWS IoT Events デベロッパーガイド\$1*」の「[DeleteDetectorModel](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-DeleteDetectorModel)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DeleteDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/delete-detector-model.html)」を参照してください。

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

次のコード例は、`delete-input` を使用する方法を示しています。

**AWS CLI**  
**入力を削除するには**  
次の `delete-input` の例では、入力を削除します。  

```
aws iotevents delete-input \
    --input-name PressureInput
```
このコマンドでは何も出力されません。  
詳細については、「*AWS IoT Events デベロッパーガイド\$1*」の「[DeleteInput](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-DeleteInput)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DeleteInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/delete-input.html)」を参照してください。

### `describe-detector-model`
<a name="iot-events-data_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 ディベロッパーガイド\$1*」の「[DescribeDetectorModel](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-DescribeDetectorModel)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DescribeDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/describe-detector-model.html)」を参照してください。

### `describe-detector`
<a name="iot-events-data_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 ディベロッパーガイド\$1*」の「[DescribeDetector](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-data-DescribeDetector)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DescribeDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/describe-detector.html)」を参照してください。

### `describe-input`
<a name="iot-events-data_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 ディベロッパーガイド\$1*」の「[DescribeInput](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-DescribeInput)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DescribeInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/describe-input.html)」を参照してください。

### `describe-logging-options`
<a name="iot-events-data_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 ディベロッパーガイド\$1*」の「[DescribeLoggingOptions](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-DescribeLoggingOptions)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[DescribeLoggingOptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/describe-logging-options.html)」を参照してください。

### `list-detector-model-versions`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[ListDetectorModelVersions](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-ListDetectorModelVersions)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListDetectorModelVersions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/list-detector-model-versions.html)」を参照してください。

### `list-detector-models`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[ListDetectorModels](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-ListDetectorModels)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListDetectorModels](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/list-detector-models.html)」を参照してください。

### `list-detectors`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[ListDetectors](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-ListDetectors)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListDetectors](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/list-detectors.html)」を参照してください。

### `list-inputs`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[ListInputs](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-ListInputs)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListInputs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/list-inputs.html)」を参照してください。

### `list-tags-for-resource`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[ListTagsForResource](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-ListTagsForResource)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/list-tags-for-resource.html)」を参照してください。

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

次のコード例は、`put-logging-options` を使用する方法を示しています。

**AWS CLI**  
**ログ記録オプションを設定するには**  
次の `list-tags-for-resource` の例では、AWS IoT Events ログ記録オプションを設定または更新します。いずれかの `loggingOptions` フィールドの値を更新する場合、変更が有効になるまでに最大で 1 分かかることに注意してください また、`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 ディベロッパーガイド\$1*」の「[PutLoggingOptions](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-PutLoggingOptions)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[PutLoggingOptions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/put-logging-options.html)」を参照してください。

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

次のコード例は、`tag-resource` を使用する方法を示しています。

**AWS CLI**  
**リソースにタグを追加するには**  
次の `tag-resource` の例では、指定されたリソースのタグを追加または変更します。タグは、リソースを管理するために使用できるメタデータです。  

```
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 デベロッパーガイド\$1*」の「[TagResource](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-TagResource)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/tag-resource.html)」を参照してください。

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

次のコード例は、`untag-resource` を使用する方法を示しています。

**AWS CLI**  
**リソースからタグを削除する**  
次の `untag-resource` の例では、指定されたタグをリソースから削除します。  

```
aws iotevents untag-resource \
    --cli-input-json file://pressureInput.untag.json
```
`pressureInput.untag.json` の内容:  

```
{
    "resourceArn": "arn:aws:iotevents:us-west-2:123456789012:input/PressureInput",
    "tagKeys": [
            "deviceType"
    ]
}
```
このコマンドでは何も出力されません。  
詳細については、「*AWS IoT Events デベロッパーガイド\$1*」の「[UntagResource](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-UntagResource)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/untag-resource.html)」を参照してください。

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

次のコード例は、`update-detector-model` を使用する方法を示しています。

**AWS CLI**  
**ディテクターモデルを更新するには**  
次の `update-detector-model` の例では、ディテクターモデルを更新します。以前のバージョンによって生成されたディテクター (インスタンス) が削除され、新しい入力が到着すると再作成されます。  

```
aws iotevents update-detector-model \
    --cli-input-json file://motorDetectorModel.update.json
```
Contents of 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 デベロッパーガイド\$1*」の「[UpdateDetectorModel](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-UpdateDetectorModel)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[UpdateDetectorModel](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/update-detector-model.html)」を参照してください。

### `update-input`
<a name="iot-events-data_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 デベロッパーガイド\$1*」の「[UpdateInput](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-commands.html#api-iotevents-UpdateInput)」を参照してください。  
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[UpdateInput](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iotevents-data/update-input.html)」を参照してください。