View a markdown version of this page

AWS IoT Things Graph 使用 的範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例。

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

AWS IoT Things Graph 使用 的範例 AWS CLI

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

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

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

主題

動作

以下程式碼範例顯示如何使用 associate-entity-to-thing。

AWS CLI

將物件與裝置建立關聯

下列 associate-entity-to-thing 範例會將物件與裝置建立關聯。此範例使用位於公有命名空間中的動作感應器裝置。

aws iotthingsgraph associate-entity-to-thing \ --thing-name "MotionSensorName" \ --entity-id "urn:tdm:aws/examples:Device:HCSR501MotionSensor"

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立和上傳模型。

以下程式碼範例顯示如何使用 create-flow-template。

AWS CLI

建立流程

下列 create-flow-template 範例會建立流程 (工作流程)。MyFlowDefinition 的值是建立流程模型的 GraphQL。

aws iotthingsgraph create-flow-template \ --definition language=GRAPHQL,text="MyFlowDefinition"

輸出:

{ "summary": { "createdAt": 1559248067.545, "id": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "revisionNumber": 1 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 CreateFlowTemplate。

以下程式碼範例顯示如何使用 create-system-instance。

AWS CLI

建立系統執行個體

以下 create-system-instance 範例會建立系統執行個體。MySystemInstanceDefinition 的值是建立系統執行個體模型的 GraphQL。

aws iotthingsgraph create-system-instance -\ --definition language=GRAPHQL,text="MySystemInstanceDefinition" \ --target CLOUD \ --flow-actions-role-arn myRoleARN

輸出:

{ "summary": { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room218", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218", "status": "NOT_DEPLOYED", "target": "CLOUD", "createdAt": 1559249315.208, "updatedAt": 1559249315.208 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

以下程式碼範例顯示如何使用 create-system-template。

AWS CLI

建立系統

下列 create-system-template 範例會建立系統。MySystemDefinition 的值是建立系統模型的 GraphQL。

aws iotthingsgraph create-system-template \ --definition language=GRAPHQL,text="MySystemDefinition"

輸出:

{ "summary": { "createdAt": 1559249776.254, "id": "urn:tdm:us-west-2/123456789012/default:System:MySystem", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:System/default/MySystem", "revisionNumber": 1 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立系統。

以下程式碼範例顯示如何使用 delete-flow-template。

AWS CLI

刪除流程

下列 delete-flow-template 範例會刪除流程 (工作流程)。

aws iotthingsgraph delete-flow-template \ --id "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteFlowTemplate。

以下程式碼範例顯示如何使用 delete-namespace。

AWS CLI

刪除命名空間

以下 delete-namespace 範例會刪除命名空間。

aws iotthingsgraph delete-namespace

輸出:

{ "namespaceArn": "arn:aws:iotthingsgraph:us-west-2:123456789012", "namespaceName": "us-west-2/123456789012/default" }

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteNamespace。

以下程式碼範例顯示如何使用 delete-system-instance。

AWS CLI

刪除系統執行個體

以下 delete-system-instance 範例會刪除系統執行個體。

aws iotthingsgraph delete-system-instance \ --id "urn:tdm:us-west-2/123456789012/default:Deployment:Room218"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

以下程式碼範例顯示如何使用 delete-system-template。

AWS CLI

刪除系統

以下 delete-system-template 範例會刪除系統。

aws iotthingsgraph delete-system-template \ --id "urn:tdm:us-west-2/123456789012/default:System:MySystem"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

以下程式碼範例顯示如何使用 deploy-system-instance。

AWS CLI

部署系統執行個體

下列 delete-system-template 範例會部署系統執行個體。

aws iotthingsgraph deploy-system-instance \ --id "urn:tdm:us-west-2/123456789012/default:Deployment:Room218"

輸出:

{ "summary": { "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment:Room218", "createdAt": 1559249776.254, "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room218", "status": "DEPLOYED_IN_TARGET", "target": "CLOUD", "updatedAt": 1559249776.254 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

以下程式碼範例顯示如何使用 deprecate-flow-template。

AWS CLI

棄用流程

下列 deprecate-flow-template 範例會取代流程 (工作流程)。

aws iotthingsgraph deprecate-flow-template \ --id "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

以下程式碼範例顯示如何使用 deprecate-system-template。

AWS CLI

棄用系統

下列 deprecate-system-template 範例會取代系統。

aws iotthingsgraph deprecate-system-template \ --id "urn:tdm:us-west-2/123456789012/default:System:MySystem"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

以下程式碼範例顯示如何使用 describe-namespace。

AWS CLI

取得命名空間的描述

下列 describe-namespace 範例會取得命名空間的描述。

aws iotthingsgraph describe-namespace

輸出:

{ "namespaceName": "us-west-2/123456789012/default", "trackingNamespaceName": "aws", "trackingNamespaceVersion": 1, "namespaceVersion": 5 }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的命名空間。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DescribeNamespace。

以下程式碼範例顯示如何使用 dissociate-entity-from-thing。

AWS CLI

取消物件與裝置的關聯

下列 dissociate-entity-from-thing 範例會取消物件與裝置的關聯。

aws iotthingsgraph dissociate-entity-from-thing \ --thing-name "MotionSensorName" \ --entity-type "DEVICE"

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立和上傳模型。

以下程式碼範例顯示如何使用 get-entities。

AWS CLI

取得實體的定義

下列 get-entities 範例會取得裝置模型的定義。

aws iotthingsgraph get-entities \ --ids "urn:tdm:aws/examples:DeviceModel:MotionSensor"

輸出:

{ "descriptions": [ { "id": "urn:tdm:aws/examples:DeviceModel:MotionSensor", "type": "DEVICE_MODEL", "createdAt": 1559256190.599, "definition": { "language": "GRAPHQL", "text": "##\n# Specification of motion sensor devices interface.\n##\ntype MotionSensor @deviceModel(id: \"urn:tdm:aws/examples:deviceModel:MotionSensor\",\n capability: \"urn:tdm:aws/examples:capability:MotionSensorCapability\") {ignore:void}" } } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立和上傳模型。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetEntities。

以下程式碼範例顯示如何使用 get-flow-template-revisions。

AWS CLI

取得流程的修訂資訊

下列 get-flow-template-revisions 範例取得流程 (工作流程) 的修訂資訊。

aws iotthingsgraph get-flow-template-revisions \ --id urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow

輸出:

{ "summaries": [ { "id": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "revisionNumber": 1, "createdAt": 1559247540.292 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

以下程式碼範例顯示如何使用 get-flow-template。

AWS CLI

取得流程定義

下列 get-flow-template 範例取得流程的定義 (工作流程)。

aws iotthingsgraph get-flow-template \ --id "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow"

輸出:

{ "description": { "summary": { "id": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "revisionNumber": 1, "createdAt": 1559247540.292 }, "definition": { "language": "GRAPHQL", "text": "{\nquery MyFlow($camera: string!, $screen: string!) @workflowType(id: \"urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow\") @annotation(type: \"tgc:FlowEvent\", id: \"sledged790c1b2bcd949e09da0c9bfc077f79d\", x: 1586, y: 653) @triggers(definition: \"{MotionSensor(description: \\\"\\\") @position(x: 1045, y: 635.6666564941406) {\\n condition(expr: \\\"devices[name == \\\\\\\"motionSensor\\\\\\\"].events[name == \\\\\\\"StateChanged\\\\\\\"].lastEvent\\\")\\n action(expr: \\\"\\\")\\n}}\") {\n variables {\n cameraResult @property(id: \"urn:tdm:aws/examples:property:CameraStateProperty\")\n }\n steps {\n step(name: \"Camera\", outEvent: [\"sledged790c1b2bcd949e09da0c9bfc077f79d\"]) @position(x: 1377, y: 638.6666564941406) {\n DeviceActivity(deviceModel: \"urn:tdm:aws/examples:deviceModel:Camera\", out: \"cameraResult\", deviceId: \"${camera}\") {\n capture\n }\n }\n step(name: \"Screen\", inEvent: [\"sledged790c1b2bcd949e09da0c9bfc077f79d\"]) @position(x: 1675.6666870117188, y: 637.9999847412109) {\n DeviceActivity(deviceModel: \"urn:tdm:aws/examples:deviceModel:Screen\", deviceId: \"${screen}\") {\n display(imageUrl: \"${cameraResult.lastClickedImage}\")\n }\n }\n }\n}\n}" }, "validatedNamespaceVersion": 5 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetFlowTemplate。

以下程式碼範例顯示如何使用 get-namespace-deletion-status。

AWS CLI

取得命名空間刪除任務的狀態

下列 get-namespace-deletion-status 範例會取得命名空間刪除任務的狀態。

aws iotthingsgraph get-namespace-deletion-status

輸出:

{ "namespaceArn": "arn:aws:iotthingsgraph:us-west-2:123456789012", "namespaceName": "us-west-2/123456789012/default" "status": "SUCCEEDED " }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的命名空間。

以下程式碼範例顯示如何使用 get-system-instance。

AWS CLI

取得系統執行個體

下列 get-system-instance 範例會取得系統執行個體的定義。

aws iotthingsgraph get-system-instance \ --id "urn:tdm:us-west-2/123456789012/default:Deployment:Room218"

輸出:

{ "description": { "summary": { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room218", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218", "status": "NOT_DEPLOYED", "target": "CLOUD", "createdAt": 1559249315.208, "updatedAt": 1559249315.208 }, "definition": { "language": "GRAPHQL", "text": "{\r\nquery Room218 @deployment(id: \"urn:tdm:us-west-2/123456789012/default:Deployment:Room218\", systemId: \"urn:tdm:us-west-2/123456789012/default:System:SecurityFlow\") {\r\n motionSensor(deviceId: \"MotionSensorName\")\r\n screen(deviceId: \"ScreenName\")\r\n camera(deviceId: \"CameraName\") \r\n triggers {MotionEventTrigger(description: \"a trigger\") { \r\n condition(expr: \"devices[name == 'motionSensor'].events[name == 'StateChanged'].lastEvent\") \r\n action(expr: \"ThingsGraph.startFlow('SecurityFlow', bindings[name == 'camera'].deviceId, bindings[name == 'screen'].deviceId)\")\r\n }\r\n }\r\n }\r\n }" }, "metricsConfiguration": { "cloudMetricEnabled": false }, "validatedNamespaceVersion": 5, "flowActionsRoleArn": "arn:aws:iam::123456789012:role/ThingsGraphRole" } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetSystemInstance。

以下程式碼範例顯示如何使用 get-system-template-revisions。

AWS CLI

取得系統的修訂資訊

下列 get-system-template-revisions 範例會取得系統的修訂資訊。

aws iotthingsgraph get-system-template-revisions \ --id "urn:tdm:us-west-2/123456789012/default:System:MySystem"

輸出:

{ "summaries": [ { "id": "urn:tdm:us-west-2/123456789012/default:System:MySystem", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:System/default/MySystem", "revisionNumber": 1, "createdAt": 1559247540.656 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

以下程式碼範例顯示如何使用 get-system-template。

AWS CLI

取得系統

下列 get-system-template 範例會取得系統的定義。

aws iotthingsgraph get-system-template \ --id "urn:tdm:us-west-2/123456789012/default:System:MySystem"

輸出:

{ "description": { "summary": { "id": "urn:tdm:us-west-2/123456789012/default:System:MySystem", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:System/default/MyFlow", "revisionNumber": 1, "createdAt": 1559247540.656 }, "definition": { "language": "GRAPHQL", "text": "{\ntype MySystem @systemType(id: \"urn:tdm:us-west-2/123456789012/default:System:MySystem\", description: \"\") {\n camera: Camera @thing(id: \"urn:tdm:aws/examples:deviceModel:Camera\")\n screen: Screen @thing(id: \"urn:tdm:aws/examples:deviceModel:Screen\")\n motionSensor: MotionSensor @thing(id: \"urn:tdm:aws/examples:deviceModel:MotionSensor\")\n MyFlow: MyFlow @workflow(id: \"urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow\")\n}\n}" }, "validatedNamespaceVersion": 5 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetSystemTemplate。

以下程式碼範例顯示如何使用 get-upload-status。

AWS CLI

取得實體上傳的狀態

下列 get-upload-status 範例會取得實體上傳操作的狀態。MyUploadId 的值是 upload-entity-definitions 操作傳回的 ID 值。

aws iotthingsgraph get-upload-status \ --upload-id "MyUploadId"

輸出:

{ "namespaceName": "us-west-2/123456789012/default", "namespaceVersion": 5, "uploadId": "f6294f1e-b109-4bbe-9073-f451a2dda2da", "uploadStatus": "SUCCEEDED" }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立實體模型。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetUploadStatus。

以下程式碼範例顯示如何使用 list-flow-execution-messages。

AWS CLI

取得流程執行中事件的相關資訊

下列 list-flow-execution-messages 範例會取得流程執行中事件的相關資訊。

aws iotthingsgraph list-flow-execution-messages \ --flow-execution-id "urn:tdm:us-west-2/123456789012/default:Workflow:SecurityFlow_2019-05-11T19:39:55.317Z_MotionSensor_69b151ad-a611-42f5-ac21-fe537f9868ad"

輸出:

{ "messages": [ { "eventType": "EXECUTION_STARTED", "messageId": "f6294f1e-b109-4bbe-9073-f451a2dda2da", "payload": "Flow execution started", "timestamp": 1559247540.656 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

以下程式碼範例顯示如何使用 list-tags-for-resource。

AWS CLI

列出資源的所有標籤

下列list-tags-for-resource範例列出 an AWS IoT Things Graph 資源的所有標籤。

aws iotthingsgraph list-tags-for-resource \ --resource-arn "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218"

輸出:

{ "tags": [ { "key": "Type", "value": "Residential" } ] }

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的標記您的 IoT Things Graph 資源。 AWS IoT

以下程式碼範例顯示如何使用 search-entities。

AWS CLI

搜尋實體

下列 search-entities 範例會搜尋類型為 EVENT 的所有實體。

aws iotthingsgraph search-entities \ --entity-types "EVENT"

輸出:

{ "descriptions": [ { "id": "urn:tdm:aws/examples:Event:MotionSensorEvent", "type": "EVENT", "definition": { "language": "GRAPHQL", "text": "##\n# Description of events emitted by motion sensor.\n##\ntype MotionSensorEvent @eventType(id: \"urn:tdm:aws/examples:event:MotionSensorEvent\",\n payload: \"urn:tdm:aws/examples:property:MotionSensorStateProperty\") {ignore:void}" } }, { "id": "urn:tdm:us-west-2/123456789012/default:Event:CameraClickedEventV2", "type": "EVENT", "definition": { "language": "GRAPHQL", "text": "type CameraClickedEventV2 @eventType(id: \"urn:tdm:us-west-2/123456789012/default:event:CameraClickedEventV2\",\r\npayload: \"urn:tdm:aws:Property:Boolean\"){ignore:void}" } }, { "id": "urn:tdm:us-west-2/123456789012/default:Event:MotionSensorEventV2", "type": "EVENT", "definition": { "language": "GRAPHQL", "text": "# Event emitted by the motion sensor.\r\ntype MotionSensorEventV2 @eventType(id: \"urn:tdm:us-west-2/123456789012/default:event:MotionSensorEventV2\",\r\npayload: \"urn:tdm:us-west-2/123456789012/default:property:MotionSensorStateProperty2\") {ignore:void}" } } ], "nextToken": "urn:tdm:us-west-2/123456789012/default:Event:MotionSensorEventV2" }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的AWS IoT Things Graph 資料模型參考。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 SearchEntities。

以下程式碼範例顯示如何使用 search-flow-executions。

AWS CLI

搜尋流程執行

下列 search-flow-executions 範例會搜尋指定系統執行個體中流程的所有執行。

aws iotthingsgraph search-flow-executions \ --system-instance-id "urn:tdm:us-west-2/123456789012/default:Deployment:Room218"

輸出:

{ "summaries": [ { "createdAt": 1559247540.656, "flowExecutionId": "f6294f1e-b109-4bbe-9073-f451a2dda2da", "flowTemplateId": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "status": "RUNNING ", "systemInstanceId": "urn:tdm:us-west-2/123456789012/default:System:MySystem", "updatedAt": 1559247540.656 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

以下程式碼範例顯示如何使用 search-flow-templates。

AWS CLI

搜尋流程 (或工作流程)

下列 search-flow-templates 範例會搜尋內含攝影機裝置模型的所有流程 (工作流程)。

aws iotthingsgraph search-flow-templates \ --filters name="DEVICE_MODEL_ID",value="urn:tdm:aws/examples:DeviceModel:Camera"

輸出:

{ "summaries": [ { "id": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "revisionNumber": 1, "createdAt": 1559247540.292 }, { "id": "urn:tdm:us-west-2/123456789012/default:Workflow:SecurityFlow", "revisionNumber": 3, "createdAt": 1548283099.27 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

以下程式碼範例顯示如何使用 search-system-instances。

AWS CLI

搜尋系統執行個體

下列 search-system-instances 範例會搜尋內含指定系統的所有系統執行個體。

aws iotthingsgraph search-system-instances \ --filters name="SYSTEM_TEMPLATE_ID",value="urn:tdm:us-west-2/123456789012/default:System:SecurityFlow"

輸出:

{ "summaries": [ { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:DeploymentForSample", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/DeploymentForSample", "status": "NOT_DEPLOYED", "target": "GREENGRASS", "greengrassGroupName": "ThingsGraphGrnGr", "createdAt": 1555716314.707, "updatedAt": 1555716314.707 }, { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:MockDeployment", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/MockDeployment", "status": "DELETED_IN_TARGET", "target": "GREENGRASS", "greengrassGroupName": "ThingsGraphGrnGr", "createdAt": 1549416462.049, "updatedAt": 1549416722.361, "greengrassGroupId": "01d04b07-2a51-467f-9d03-0c90b3cdcaaf", "greengrassGroupVersionId": "7365aed7-2d3e-4d13-aad8-75443d45eb05" }, { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:MockDeployment2", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/MockDeployment2", "status": "DEPLOYED_IN_TARGET", "target": "GREENGRASS", "greengrassGroupName": "ThingsGraphGrnGr", "createdAt": 1549572385.774, "updatedAt": 1549572418.408, "greengrassGroupId": "01d04b07-2a51-467f-9d03-0c90b3cdcaaf", "greengrassGroupVersionId": "bfa70ab3-2bf7-409c-a4d4-bc8328ae5b86" }, { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room215", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room215", "status": "NOT_DEPLOYED", "target": "GREENGRASS", "greengrassGroupName": "ThingsGraphGG", "createdAt": 1547056918.413, "updatedAt": 1547056918.413 }, { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room218", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218", "status": "NOT_DEPLOYED", "target": "CLOUD", "createdAt": 1559249315.208, "updatedAt": 1559249315.208 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用系統和流程組態。

以下程式碼範例顯示如何使用 search-system-templates。

AWS CLI

搜尋系統

下列 search-system-templates 範例會搜尋內含指定流程的所有系統。

aws iotthingsgraph search-system-templates \ --filters name="FLOW_TEMPLATE_ID",value="urn:tdm:us-west-2/123456789012/default:Workflow:SecurityFlow"

輸出:

{ "summaries": [ { "id": "urn:tdm:us-west-2/123456789012/default:System:SecurityFlow", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:System/default/SecurityFlow", "revisionNumber": 1, "createdAt": 1548283099.433 } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

以下程式碼範例顯示如何使用 search-things。

AWS CLI

搜尋與裝置和裝置模型相關聯的物件

下列 search-things 範例會搜尋與 HCSR501MotionSensor 裝置相關聯的所有物件。

aws iotthingsgraph search-things \ --entity-id "urn:tdm:aws/examples:Device:HCSR501MotionSensor"

輸出:

{ "things": [ { "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MotionSensor1", "thingName": "MotionSensor1" }, { "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/TG_MS", "thingName": "TG_MS" } ] }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立和上傳模型。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 SearchThings。

以下程式碼範例顯示如何使用 tag-resource。

AWS CLI

建立資源的標籤

下列 tag-resource 範例會為指定的資源建立標籤。

aws iotthingsgraph tag-resource \ --resource-arn "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218" \ --tags key="Type",value="Residential"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的標記您的 IoT Things Graph 資源。 AWS IoT

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource。

以下程式碼範例顯示如何使用 undeploy-system-instance。

AWS CLI

將系統執行個體從其目標取消部署

下列 undeploy-system-instance 範例會將系統執行個體從其目標中移除。

aws iotthingsgraph undeploy-system-instance \ --id "urn:tdm:us-west-2/123456789012/default:Deployment:Room215"

輸出:

{ "summary": { "id": "urn:tdm:us-west-2/123456789012/default:Deployment:Room215", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room215", "status": "PENDING_DELETE", "target": "GREENGRASS", "greengrassGroupName": "ThingsGraphGrnGr", "createdAt": 1553189694.255, "updatedAt": 1559344549.601, "greengrassGroupId": "01d04b07-2a51-467f-9d03-0c90b3cdcaaf", "greengrassGroupVersionId": "731b371d-d644-4b67-ac64-3934e99b75d7" } }

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的 IoT Things Graph 實體、流程、系統和部署的生命週期管理。 AWS IoT

以下程式碼範例顯示如何使用 untag-resource。

AWS CLI

移除資源的標籤

下列 untag-resource 範例會移除指定資源的標籤。

aws iotthingsgraph untag-resource \ --resource-arn "arn:aws:iotthingsgraph:us-west-2:123456789012:Deployment/default/Room218" \ --tag-keys "Type"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Things Graph 使用者指南中的標記您的 IoT Things Graph 資源。 AWS IoT

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource。

以下程式碼範例顯示如何使用 update-flow-template。

AWS CLI

更新流程

下列 update-flow-template 範例會更新流程 (工作流程)。MyFlowDefinition 的值是建立流程模型的 GraphQL。

aws iotthingsgraph update-flow-template \ --id "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow" \ --definition language=GRAPHQL,text="MyFlowDefinition"

輸出:

{ "summary": { "createdAt": 1559248067.545, "id": "urn:tdm:us-west-2/123456789012/default:Workflow:MyFlow", "revisionNumber": 2 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的使用流程。

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UpdateFlowTemplate。

以下程式碼範例顯示如何使用 update-system-template。

AWS CLI

更新系統

下列 update-system-template 範例會更新系統。MySystemDefinition 的值是建立系統模型的 GraphQL。

aws iotthingsgraph update-system-template \ --id "urn:tdm:us-west-2/123456789012/default:System:MySystem" \ --definition language=GRAPHQL,text="MySystemDefinition"

輸出:

{ "summary": { "createdAt": 1559249776.254, "id": "urn:tdm:us-west-2/123456789012/default:System:MySystem", "arn": "arn:aws:iotthingsgraph:us-west-2:123456789012:System/default/MySystem", "revisionNumber": 2 } }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立系統。

以下程式碼範例顯示如何使用 upload-entity-definitions。

AWS CLI

上傳實體定義

下列 upload-entity-definitions 範例會將實體定義上傳至命名空間。MyEntityDefinitions 的值是建立實體模型的 GraphQL。

aws iotthingsgraph upload-entity-definitions \ --document language=GRAPHQL,text="MyEntityDefinitions"

輸出:

{ "uploadId": "f6294f1e-b109-4bbe-9073-f451a2dda2da" }

如需詳細資訊,請參閱《AWS IoT Things Graph 使用者指南》中的建立實體模型。