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

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

Amazon IoT Greengrass V2 使用示例 Amazon CLI

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

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

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

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

主题

操作

以下代码示例演示如何使用 associate-service-role-to-account

Amazon CLI

将 Greengrass 服务角色与您的账户关联 Amazon

以下associate-service-role-to-account示例将您的账户的服务角色与 Amazon IoT Greengrass 关联起来。 Amazon

aws greengrassv2 associate-service-role-to-account \ --role-arn arn:aws:iam::123456789012:role/service-role/Greengrass_ServiceRole

输出:

{ "associatedAt": "2022-01-19T19:21:53Z" }

有关更多信息,请参阅《物Amazon 联Greengrass V2 开发者指南》中的 Greengrass 服务角色。

以下代码示例演示如何使用 batch-associate-client-device-with-core-device

Amazon CLI

将客户端设备与核心设备关联

以下batch-associate-client-device-with-core-device示例将两台客户端设备与一台核心设备关联起来。

aws greengrassv2 batch-associate-client-device-with-core-device \ --core-device-thing-name MyGreengrassCore \ --entries thingName=MyClientDevice1 thingName=MyClientDevice2

输出:

{ "errorEntries": [] }

有关更多信息,请参阅 IoT Greengrass V2 开发者指南中的与本地Amazon 物联网设备交互

以下代码示例演示如何使用 batch-disassociate-client-device-from-core-device

Amazon CLI

取消客户端设备与核心设备的关联

以下batch-disassociate-client-device-from-core-device示例取消两台客户端设备与核心设备的关联。

aws greengrassv2 batch-disassociate-client-device-from-core-device \ --core-device-thing-name MyGreengrassCore \ --entries thingName=MyClientDevice1 thingName=MyClientDevice2

输出:

{ "errorEntries": [] }

有关更多信息,请参阅 IoT Greengrass V2 开发者指南中的与本地Amazon 物联网设备交互

以下代码示例演示如何使用 cancel-deployment

Amazon CLI

取消部署

以下cancel-deployment示例停止了对事物组的持续部署。

aws greengrassv2 cancel-deployment \ --deployment-id a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "message": "SUCCESS" }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的取消部署

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

以下代码示例演示如何使用 create-component-version

Amazon CLI

示例 1:根据配方创建组件版本

以下create-component-version示例根据配方文件创建 Hello World 组件的版本。

aws greengrassv2 create-component-version \ --inline-recipe fileb://com.example.HelloWorld-1.0.0.json

com.example.HelloWorld-1.0.0.json 的内容:

{ "RecipeFormatVersion": "2020-01-25", "ComponentName": "com.example.HelloWorld", "ComponentVersion": "1.0.0", "ComponentDescription": "My first AWS IoT Greengrass component.", "ComponentPublisher": "Amazon", "ComponentConfiguration": { "DefaultConfiguration": { "Message": "world" } }, "Manifests": [ { "Platform": { "os": "linux" }, "Lifecycle": { "Run": "echo 'Hello {configuration:/Message}'" } } ] }

输出:

{ "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2021-01-07T16:24:33.650000-08:00", "status": { "componentState": "REQUESTED", "message": "NONE", "errors": {} } }

有关更多信息,请参阅《Amazon IoT Greengrass V2 开发者指南》中的创建自定义组件和上传要部署的组件。

示例 2:通过 Amazon Lambda 函数创建组件版本

以下create-component-version示例通过 Amazon Lambda 函数创建 Hello World 组件的一个版本。

aws greengrassv2 create-component-version \ --cli-input-json file://lambda-function-component.json

lambda-function-component.json 的内容:

{ "lambdaFunction": { "lambdaArn": "arn:aws:lambda:us-west-2:123456789012:function:HelloWorldPythonLambda:1", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "componentLambdaParameters": { "eventSources": [ { "topic": "hello/world/+", "type": "IOT_CORE" } ] } } }

输出:

{ "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2021-01-07T17:05:27.347000-08:00", "status": { "componentState": "REQUESTED", "message": "NONE", "errors": {} } }

有关更多信息,请参阅物联网 Amazon Greengrass Amazon V2 开发人员指南中的运行 Lambda 函数

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

Amazon CLI

示例 1:创建部署

以下create-deployment示例将 Amazon IoT Greengrass 命令行接口部署到核心设备。

aws greengrassv2 create-deployment \ --cli-input-json file://cli-deployment.json

cli-deployment.json 的内容:

{ "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore", "deploymentName": "Deployment for MyGreengrassCore", "components": { "aws.greengrass.Cli": { "componentVersion": "2.0.3" } }, "deploymentPolicies": { "failureHandlingPolicy": "DO_NOTHING", "componentUpdatePolicy": { "timeoutInSeconds": 60, "action": "NOTIFY_COMPONENTS" }, "configurationValidationPolicy": { "timeoutInSeconds": 60 } }, "iotJobConfiguration": {} }

输出:

{ "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发人员指南中的创建部署

示例 2:创建更新组件配置的部署

以下create-deployment示例将 Amazon IoT Greengrass 核心组件部署到一组核心设备。此部署对 nucleus 组件应用了以下配置更新:

将目标设备的代理设置重置为默认的无代理设置。将目标设备的 MQTT 设置重置为默认值。为 nucleus 的 jvm 设置 JVM 选项。设置 nucleus 的日志级别。

aws greengrassv2 create-deployment \ --cli-input-json file://nucleus-deployment.json

nucleus-deployment.json 的内容:

{ "targetArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/MyGreengrassCoreGroup", "deploymentName": "Deployment for MyGreengrassCoreGroup", "components": { "aws.greengrass.Nucleus": { "componentVersion": "2.0.3", "configurationUpdate": { "reset": [ "/networkProxy", "/mqtt" ], "merge": "{\"jvmOptions\":\"-Xmx64m\",\"logging\":{\"level\":\"WARN\"}}" } } }, "deploymentPolicies": { "failureHandlingPolicy": "ROLLBACK", "componentUpdatePolicy": { "timeoutInSeconds": 60, "action": "NOTIFY_COMPONENTS" }, "configurationValidationPolicy": { "timeoutInSeconds": 60 } }, "iotJobConfiguration": {} }

输出:

{ "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "iotJobId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "iotJobArn": "arn:aws:iot:us-west-2:123456789012:job/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发人员指南中的创建部署和更新组件配置。

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

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

Amazon CLI

删除组件版本

以下delete-component示例删除了 Hello World 组件。

aws greengrassv2 delete-component \ --arn arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0

此命令不生成任何输出。

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

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

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

Amazon CLI

删除核心设备

以下delete-core-device示例删除了 Amazon 物联网 Greengrass 核心设备。

aws greengrassv2 delete-core-device \ --core-device-thing-name MyGreengrassCore

此命令不生成任何输出。

有关更多信息,请参阅《 Amazon 物联网 Greengrass V2 开发者指南》中的卸载 Io Amazon T Greengrass Core 软件。

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

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

Amazon CLI

描述组件版本

以下describe-component示例描述了 Hello World 组件。

aws greengrassv2 describe-component \ --arn arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0

输出:

{ "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0", "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "creationTimestamp": "2021-01-07T17:12:11.133000-08:00", "publisher": "Amazon", "description": "My first AWS IoT Greengrass component.", "status": { "componentState": "DEPLOYABLE", "message": "NONE", "errors": {} }, "platforms": [ { "attributes": { "os": "linux" } } ] }

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

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

以下代码示例演示如何使用 disassociate-service-role-from-account

Amazon CLI

解除 Greengrass 服务角色与您的账户的关联 Amazon

以下disassociate-service-role-from-account示例取消您账户的 Greengrass 服务角色与 Amazon IoT Greengrass 的关联。 Amazon

aws greengrassv2 disassociate-service-role-from-account

输出:

{ "disassociatedAt": "2022-01-19T19:26:09Z" }

有关更多信息,请参阅《物Amazon 联Greengrass V2 开发者指南》中的 Greengrass 服务角色。

以下代码示例演示如何使用 get-component-version-artifact

Amazon CLI

获取用于下载组件工件的 URL

以下get-component-version-artifact示例获取了下载本地调试控制台组件的 JAR 文件的 URL。

aws greengrassv2 get-component-version-artifact \ --arn arn:aws:greengrass:us-west-2:aws:components:aws.greengrass.LocalDebugConsole:versions:2.0.3 \ --artifact-name "Uvt6ZEzQ9TKiAuLbfXBX_APdY0TWks3uc46tHFHTzBM=/aws.greengrass.LocalDebugConsole.jar"

输出:

{ "preSignedUrl": "https://evergreencomponentmanageme-artifactbucket7410c9ef-g18n1iya8kwr.s3.us-west-2.amazonaws.com/public/aws.greengrass.LocalDebugConsole/2.0.3/s3/ggv2-component-releases-prod-pdx/EvergreenHttpDebugView/2ffc496ba41b39568968b22c582b4714a937193ee7687a45527238e696672521/aws.greengrass.LocalDebugConsole/aws.greengrass.LocalDebugConsole.jar?X-Amz-Security-Token=KwfLKSdEXAMPLE..." }

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

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

Amazon CLI

示例 1:以 YAML 格式下载组件的配方(Linux、macOS 或 Unix)

以下get-component示例将 Hello World 组件的配方下载到 YAML 格式的文件中。此命令执行以下操作:

使用--output--query参数来控制命令的输出。这些参数从命令的输出中提取配方 blob。有关控制输出的更多信息,请参阅《命令行界面用户指南》中的控制Amazon 命令输出。使用该base64实用程序。此实用程序将提取的 blob 解码为原始文本。成功的get-component命令返回的 blob 是 base64 编码的文本。必须解码此 blob 才能获得原始文本。将解码后的文本保存到文件中。命令的最后一部分 (> com.example.HelloWorld-1.0.0.json) 将解码后的文本保存到文件中。

aws greengrassv2 get-component \ --arn arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0 \ --recipe-output-format YAML \ --query recipe \ --output text | base64 --decode > com.example.HelloWorld-1.0.0.json

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

示例 2:以 YAML 格式下载组件的配方 (Windows CMD)

以下get-component示例将 Hello World 组件的配方下载到 YAML 格式的文件中。此命令使用该certutil实用程序。

aws greengrassv2 get-component ^ --arn arn:aws:greengrass:us-west-2:675946970638:components:com.example.HelloWorld:versions:1.0.0 ^ --recipe-output-format YAML ^ --query recipe ^ --output text > com.example.HelloWorld-1.0.0.yaml.b64 certutil -decode com.example.HelloWorld-1.0.0.yaml.b64 com.example.HelloWorld-1.0.0.yaml

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

示例 3:以 YAML 格式下载组件的配方 (Windows PowerShell)

以下get-component示例将 Hello World 组件的配方下载到 YAML 格式的文件中。此命令使用该certutil实用程序。

aws greengrassv2 get-component ` --arn arn:aws:greengrass:us-west-2:675946970638:components:com.example.HelloWorld:versions:1.0.0 ` --recipe-output-format YAML ` --query recipe ` --output text > com.example.HelloWorld-1.0.0.yaml.b64 certutil -decode com.example.HelloWorld-1.0.0.yaml.b64 com.example.HelloWorld-1.0.0.yaml

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

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

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

Amazon CLI

获取 Greengrass 核心设备的连接信息

以下get-connectivity-info示例获取了 Greengrass 核心设备的连接信息。客户端设备使用此信息连接到在此核心设备上运行的 MQTT 代理。

aws greengrassv2 get-connectivity-info \ --thing-name MyGreengrassCore

输出:

{ "connectivityInfo": [ { "id": "localIP_192.0.2.0", "hostAddress": "192.0.2.0", "portNumber": 8883 } ] }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的管理核心设备端点

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

Amazon CLI

获取核心设备

以下get-core-device示例获取有关 Amazon 物联网 Greengrass 核心设备的信息。

aws greengrassv2 get-core-device \ --core-device-thing-name MyGreengrassCore

输出:

{ "coreDeviceThingName": "MyGreengrassCore", "coreVersion": "2.0.3", "platform": "linux", "architecture": "amd64", "status": "HEALTHY", "lastStatusUpdateTimestamp": "2021-01-08T04:57:58.838000-08:00", "tags": {} }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的检查核心设备状态

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

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

Amazon CLI

要进行部署

以下get-deployment示例获取有关将 Amazon 物联网 Greengrass nucleus 组件部署到一组核心设备的信息。

aws greengrassv2 get-deployment \ --deployment-id a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "targetArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/MyGreengrassCoreGroup", "revisionId": "14", "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "deploymentName": "Deployment for MyGreengrassCoreGroup", "deploymentStatus": "ACTIVE", "iotJobId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "iotJobArn": "arn:aws:iot:us-west-2:123456789012:job/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "components": { "aws.greengrass.Nucleus": { "componentVersion": "2.0.3", "configurationUpdate": { "merge": "{\"jvmOptions\":\"-Xmx64m\",\"logging\":{\"level\":\"WARN\"}}", "reset": [ "/networkProxy", "/mqtt" ] } } }, "deploymentPolicies": { "failureHandlingPolicy": "ROLLBACK", "componentUpdatePolicy": { "timeoutInSeconds": 60, "action": "NOTIFY_COMPONENTS" }, "configurationValidationPolicy": { "timeoutInSeconds": 60 } }, "iotJobConfiguration": {}, "creationTimestamp": "2021-01-07T17:21:20.691000-08:00", "isLatestForTarget": false, "tags": {} }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发人员指南中的将组件部署到设备

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

以下代码示例演示如何使用 get-service-role-for-account

Amazon CLI

为你的账户获取 Greengrass 服务角色 Amazon

以下get-service-role-for-account示例为您的账户获取与 Amazon IoT Greengrass 关联的服务角色。 Amazon

aws greengrassv2 get-service-role-for-account

输出:

{ "associatedAt": "2022-01-19T19:21:53Z", "roleArn": "arn:aws:iam::123456789012:role/service-role/Greengrass_ServiceRole" }

有关更多信息,请参阅《物Amazon 联Greengrass V2 开发者指南》中的 Greengrass 服务角色。

以下代码示例演示如何使用 list-client-devices-associated-with-core-device

Amazon CLI

列出与核心设备关联的客户端设备

以下list-client-devices-associated-with-core-device示例列出了与核心设备关联的所有客户端设备。

aws greengrassv2 list-client-devices-associated-with-core-device \ --core-device-thing-name MyTestGreengrassCore

输出:

{ "associatedClientDevices": [ { "thingName": "MyClientDevice2", "associationTimestamp": "2021-07-12T16:33:55.843000-07:00" }, { "thingName": "MyClientDevice1", "associationTimestamp": "2021-07-12T16:33:55.843000-07:00" } ] }

有关更多信息,请参阅 IoT Greengrass V2 开发者指南中的与本地Amazon 物联网设备交互

以下代码示例演示如何使用 list-component-versions

Amazon CLI

列出组件的版本

以下list-component-versions示例列出了 Hello World 组件的所有版本。

aws greengrassv2 list-component-versions \ --arn arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld

输出:

{ "componentVersions": [ { "componentName": "com.example.HelloWorld", "componentVersion": "1.0.1", "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.1" }, { "componentName": "com.example.HelloWorld", "componentVersion": "1.0.0", "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.0" } ] }

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

以下代码示例演示如何使用 list-components

Amazon CLI

列出组件

以下list-components示例列出了您在当前区域的 Amazon 账户中定义的每个组件及其最新版本。

aws greengrassv2 list-components

输出:

{ "components": [ { "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld", "componentName": "com.example.HelloWorld", "latestVersion": { "arn": "arn:aws:greengrass:us-west-2:123456789012:components:com.example.HelloWorld:versions:1.0.1", "componentVersion": "1.0.1", "creationTimestamp": "2021-01-08T16:51:07.352000-08:00", "description": "My first AWS IoT Greengrass component.", "publisher": "Amazon", "platforms": [ { "attributes": { "os": "linux" } } ] } } ] }

有关更多信息,请参阅《Amazon 物联网 Greengrass V2 开发者指南》中的管理组件

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

以下代码示例演示如何使用 list-core-devices

Amazon CLI

列出核心设备

以下list-core-devices示例列出了 Amazon 您账户中 Amazon 当前区域的 IoT Greengrass 核心设备。

aws greengrassv2 list-core-devices

输出:

{ "coreDevices": [ { "coreDeviceThingName": "MyGreengrassCore", "status": "HEALTHY", "lastStatusUpdateTimestamp": "2021-01-08T04:57:58.838000-08:00" } ] }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的检查核心设备状态

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

以下代码示例演示如何使用 list-deployments

Amazon CLI

列出部署

以下list-deployments示例列出了您在当前区域的 Amazon 账户中定义的每个部署的最新版本。

aws greengrassv2 list-deployments

输出:

{ "deployments": [ { "targetArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/MyGreengrassCoreGroup", "revisionId": "14", "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "deploymentName": "Deployment for MyGreengrassCoreGroup", "creationTimestamp": "2021-01-07T17:21:20.691000-08:00", "deploymentStatus": "ACTIVE", "isLatestForTarget": false }, { "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore", "revisionId": "1", "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "deploymentName": "Deployment for MyGreengrassCore", "creationTimestamp": "2021-01-06T16:10:42.407000-08:00", "deploymentStatus": "COMPLETED", "isLatestForTarget": false } ] }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发人员指南中的将组件部署到设备

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

以下代码示例演示如何使用 list-effective-deployments

Amazon CLI

列出部署任务

以下list-effective-deployments示例列出了适用于 Amazon 物联网 Greengrass 核心设备的部署。

aws greengrassv2 list-effective-deployments \ --core-device-thing-name MyGreengrassCore

输出:

{ "effectiveDeployments": [ { "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "deploymentName": "Deployment for MyGreengrassCore", "iotJobId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "targetArn": "arn:aws:iot:us-west-2:123456789012:thing/MyGreengrassCore", "coreDeviceExecutionStatus": "COMPLETED", "reason": "SUCCESSFUL", "creationTimestamp": "2021-01-06T16:10:42.442000-08:00", "modifiedTimestamp": "2021-01-08T17:21:27.830000-08:00" }, { "deploymentId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "deploymentName": "Deployment for MyGreengrassCoreGroup", "iotJobId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE44444", "iotJobArn": "arn:aws:iot:us-west-2:123456789012:job/a1b2c3d4-5678-90ab-cdef-EXAMPLE44444", "targetArn": "arn:aws:iot:us-west-2:123456789012:thinggroup/MyGreengrassCoreGroup", "coreDeviceExecutionStatus": "SUCCEEDED", "reason": "SUCCESSFUL", "creationTimestamp": "2021-01-07T17:19:20.394000-08:00", "modifiedTimestamp": "2021-01-07T17:21:20.721000-08:00" } ] }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的检查核心设备状态

以下代码示例演示如何使用 list-installed-components

Amazon CLI

列出安装在核心设备上的组件

以下list-installed-components示例列出了安装在 Amazon 物联网 Greengrass 核心设备上的组件。

aws greengrassv2 list-installed-components \ --core-device-thing-name MyGreengrassCore

输出:

{ "installedComponents": [ { "componentName": "aws.greengrass.Cli", "componentVersion": "2.0.3", "lifecycleState": "RUNNING", "isRoot": true }, { "componentName": "aws.greengrass.Nucleus", "componentVersion": "2.0.3", "lifecycleState": "FINISHED", "isRoot": true } ] }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的检查核心设备状态

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

Amazon CLI

列出资源的标签

以下list-tags-for-resource示例列出了 Amazon 物联网 Greengrass 核心设备的所有标签。

aws greengrassv2 list-tags-for-resource \ --resource-arn arn:aws:greengrass:us-west-2:123456789012:coreDevices:MyGreengrassCore

输出:

{ "tags": { "Owner": "richard-roe" } }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的为资源添加标签

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

Amazon CLI

要将标签添加到资源中

以下tag-resource示例向 Amazon 物联网 Greengrass 核心设备添加所有者标签。您可以使用此标签根据谁拥有核心设备来控制对核心设备的访问权限。

aws greengrassv2 tag-resource \ --resource-arn arn:aws:greengrass:us-west-2:123456789012:coreDevices:MyGreengrassCore \ --tags Owner=richard-roe

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的为资源添加标签

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

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

Amazon CLI

从资源中移除标签

以下untag-resource示例从 Amazon 物联网 Greengrass 核心设备中移除所有者标签。

aws iotsitewise untag-resource \ --resource-arn arn:aws:greengrass:us-west-2:123456789012:coreDevices:MyGreengrassCore \ --tag-keys Owner

此命令不生成任何输出。

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的为资源添加标签

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

以下代码示例演示如何使用 update-connectivity-info

Amazon CLI

更新 Greengrass 核心设备的连接信息

以下update-connectivity-info示例获取了 Greengrass 核心设备的连接信息。客户端设备使用此信息连接到在此核心设备上运行的 MQTT 代理。

aws greengrassv2 update-connectivity-info \ --thing-name MyGreengrassCore \ --cli-input-json file://core-device-connectivity-info.json

core-device-connectivity-info.json 的内容:

{ "connectivityInfo": [ { "hostAddress": "192.0.2.0", "portNumber": 8883, "id": "localIP_192.0.2.0" } ] }

输出:

{ "version": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

有关更多信息,请参阅 Amazon IoT Greengrass V2 开发者指南中的管理核心设备端点