Amazon IoT Things Graph 使用示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon IoT Things Graph 使用示例 Amazon CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 Amazon IoT Things Graph。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 associate-entity-to-thing

Amazon CLI

将事物与设备关联

以下associate-entity-to-thing示例将事物与设备关联。该示例使用公共命名空间中的运动传感器设备。

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

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的创建和上传模型

以下代码示例演示如何使用 create-flow-template

Amazon 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 } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateFlowTemplate中的。

以下代码示例演示如何使用 create-system-instance

Amazon 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 } }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

以下代码示例演示如何使用 create-system-template

Amazon 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 } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的创建系统

以下代码示例演示如何使用 delete-flow-template

Amazon CLI

删除流程

以下delete-flow-template示例删除流程(工作流程)。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteFlowTemplate中的。

以下代码示例演示如何使用 delete-namespace

Amazon CLI

删除命名空间

以下delete-namespace示例删除命名空间。

aws iotthingsgraph delete-namespace

输出:

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

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteNamespace中的。

以下代码示例演示如何使用 delete-system-instance

Amazon CLI

删除系统实例

以下delete-system-instance示例删除系统实例。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

以下代码示例演示如何使用 delete-system-template

Amazon CLI

删除系统

以下delete-system-template示例删除了一个系统。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

以下代码示例演示如何使用 deploy-system-instance

Amazon 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 } }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

以下代码示例演示如何使用 deprecate-flow-template

Amazon CLI

弃用流程

以下deprecate-flow-template示例弃用了流程(工作流程)。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

以下代码示例演示如何使用 deprecate-system-template

Amazon CLI

弃用系统

以下deprecate-system-template示例不推荐使用系统。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

以下代码示例演示如何使用 describe-namespace

Amazon CLI

获取命名空间的描述

以下describe-namespace示例获取了您的命名空间的描述。

aws iotthingsgraph describe-namespace

输出:

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

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的命名空间

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeNamespace中的。

以下代码示例演示如何使用 dissociate-entity-from-thing

Amazon CLI

将事物与设备断开关联

以下dissociate-entity-from-thing示例将事物与设备解除关联。

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

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的创建和上传模型

以下代码示例演示如何使用 get-entities

Amazon 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}" } } ] }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的创建和上传模型

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetEntities中的。

以下代码示例演示如何使用 get-flow-template-revisions

Amazon 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 } ] }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

以下代码示例演示如何使用 get-flow-template

Amazon 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 } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetFlowTemplate中的。

以下代码示例演示如何使用 get-namespace-deletion-status

Amazon 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 " }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的命名空间

以下代码示例演示如何使用 get-system-instance

Amazon 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" } }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetSystemInstance中的。

以下代码示例演示如何使用 get-system-template-revisions

Amazon 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 } ] }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

以下代码示例演示如何使用 get-system-template

Amazon 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 } }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetSystemTemplate中的。

以下代码示例演示如何使用 get-upload-status

Amazon CLI

要获取实体的状态,请上传

以下get-upload-status示例获取您的实体上传操作的状态。的值MyUploadIdupload-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" }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的建模实体

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUploadStatus中的。

以下代码示例演示如何使用 list-flow-execution-messages

Amazon 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 } ] }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

以下代码示例演示如何使用 list-tags-for-resource

Amazon CLI

列出资源的所有标签

以下list-tags-for-resource示例列出了 Amazon 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" } ] }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的为Amazon 物联网事物图表资源添加标签

以下代码示例演示如何使用 search-entities

Amazon 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" }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的Amazon IoT Things Graph 数据模型参考

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考SearchEntities中的。

以下代码示例演示如何使用 search-flow-executions

Amazon 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 } ] }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

以下代码示例演示如何使用 search-flow-templates

Amazon 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 } ] }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

以下代码示例演示如何使用 search-system-instances

Amazon 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 } ] }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的使用系统和流程配置

以下代码示例演示如何使用 search-system-templates

Amazon 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 } ] }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

以下代码示例演示如何使用 search-things

Amazon CLI

搜索与设备和设备型号相关的内容

以下search-things示例搜索与 HCSR501 MotionSensor 设备关联的所有内容。

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" } ] }

有关更多信息,请参阅 Amazon IoT Things Graph 用户指南中的创建和上传模型

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考SearchThings中的。

以下代码示例演示如何使用 tag-resource

Amazon CLI

为资源创建标签

以下tag-resource示例为指定资源创建标签。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的为Amazon 物联网事物图表资源添加标签

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考TagResource中的。

以下代码示例演示如何使用 undeploy-system-instance

Amazon 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" } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的 IoT Things Graph Graph 实体、流程、系统和部署的生命周期管理。Amazon

以下代码示例演示如何使用 untag-resource

Amazon CLI

移除资源的标签

以下untag-resource示例删除了指定资源的标签。

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

此命令不生成任何输出。

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的为Amazon 物联网事物图表资源添加标签

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UntagResource中的。

以下代码示例演示如何使用 update-flow-template

Amazon 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 } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的使用流程

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateFlowTemplate中的。

以下代码示例演示如何使用 update-system-template

Amazon 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 } }

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的创建系统

以下代码示例演示如何使用 upload-entity-definitions

Amazon CLI

上传实体定义

以下upload-entity-definitions示例将实体定义上传到您的命名空间。的值MyEntityDefinitions是对实体进行建模的 GraphQL。

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

输出:

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

有关更多信息,请参阅《Amazon IoT Things Graph 用户指南》中的建模实体