AWS IoT Events-Data を使用した の例 AWS CLI - AWS Command Line Interface

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS IoT Events-Data を使用した の例 AWS CLI

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

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

各例には、完全なソースコードへのリンクが含まれています。このリンクには、コンテキスト内でコードをセットアップして実行する方法の手順が記載されています。

トピック

アクション

次のコード例は、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 デベロッパーガイドBatchPutMessage*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスBatchPutMessage」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドBatchUpdateDetector*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスBatchUpdateDetector」の「」を参照してください。 AWS CLI

次のコード例は、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 > 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" }, "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 デベロッパーガイドCreateDetectorModel*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスCreateDetectorModel」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドCreateInput*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスCreateInput」の「」を参照してください。 AWS CLI

次の例は、delete-detector-model を使用する方法を説明しています。

AWS CLI

ディテクターモデルを削除するには

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

aws iotevents delete-detector-model \ --detector-model-name motorDetectorModel*

このコマンドでは何も出力されません。

詳細については、AWS 「 IoT Events デベロッパーガイドDeleteDetectorModel」の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDeleteDetectorModel」の「」を参照してください。 AWS CLI

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

AWS CLI

入力を削除するには

次のdelete-input例では、入力を削除します。

aws iotevents delete-input \ --input-name PressureInput

このコマンドでは何も出力されません。

詳細については、 AWS IoT Events デベロッパーガイドDeleteInput*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDeleteInput」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドDescribeDetectorModel*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDescribeDetectorModel」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドDescribeDetector*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDescribeDetector」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドDescribeInput*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDescribeInput」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドDescribeLoggingOptions*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスDescribeLoggingOptions」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドListDetectorModelVersions*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスListDetectorModelVersions」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドListDetectorModels*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスListDetectorModels」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドListDetectors*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスListDetectors」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドListInputs*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスListInputs」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドListTagsForResource*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスListTagsForResource」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドPutLoggingOptions」の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスPutLoggingOptions」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドTagResource*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスTagResource」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドUntagResource*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスUntagResource」の「」を参照してください。 AWS CLI

次のコード例は、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 デベロッパーガイドUpdateDetectorModel」の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスUpdateDetectorModel」の「」を参照してください。 AWS CLI

次の例は、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 デベロッパーガイドUpdateInput*の「」を参照してください。

  • API 詳細については、「 コマンドリファレンスUpdateInput」の「」を参照してください。 AWS CLI