AWS IoT Greengrass 使用範例 AWS CLI - AWS Command Line Interface

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

AWS IoT Greengrass 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 AWS IoT Greengrass。

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

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用associate-role-to-group

AWS CLI

若要建立角色與綠色群組的關聯

下列associate-role-to-group範例會將指定的 IAM 角色與 Greengrass 群組產生關聯。本機 Lambda 函數和連接器會使用群組角色來存取 AWS 服務。例如,您的群組角色可能會授與 CloudWatch 記錄整合所需的權限。

aws greengrass associate-role-to-group \ --group-id 2494ee3f-7f8a-4e92-a78b-d205f808b84b \ --role-arn arn:aws:iam::123456789012:role/GG-Group-Role

輸出:

{ "AssociatedAt": "2019-09-10T20:03:30Z" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定群組角色

下列程式碼範例會示範如何使用associate-service-role-to-account

AWS CLI

將服務角色與您的 AWS 帳戶建立關聯

下列associate-service-role-to-account範例會將由其 ARN 指定的 IAM 服務角色與您帳戶中的 AWS IoT Greengrass 建立關聯。 AWS 您必須先前在 IAM 中建立服務角色,並且必須將政策文件與該文件建立關聯,以允許 AWS IoT Greengrass 擔任此角色。

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

輸出:

{ "AssociatedAt": "2019-06-25T18:12:45Z" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的《Gre engrass 服務角色》。

下列程式碼範例會示範如何使用create-connector-definition-version

AWS CLI

建立連接器定義版本

下列create-connector-definition-version範例會建立連接器定義版本,並將其與指定的連接器定義相關聯。版本中的所有連接器都會定義其參數的值。

aws greengrass create-connector-definition-version \ --connector-definition-id "55d0052b-0d7d-44d6-b56f-21867215e118" \ --connectors "[{\"Id\": \"MyTwilioNotificationsConnector\", \"ConnectorArn\": \"arn:aws:greengrass:us-west-2::/connectors/TwilioNotifications/versions/2\", \"Parameters\": {\"TWILIO_ACCOUNT_SID\": \"AC1a8d4204890840d7fc482aab38090d57\", \"TwilioAuthTokenSecretArn\": \"arn:aws:secretsmanager:us-west-2:123456789012:secret:greengrass-TwilioAuthToken-ntSlp6\", \"TwilioAuthTokenSecretArn-ResourceId\": \"TwilioAuthToken\", \"DefaultFromPhoneNumber\": \"4254492999\"}}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/55d0052b-0d7d-44d6-b56f-21867215e118/versions/33f709a0-c825-49cb-9eea-dc8964fbd635", "CreationTimestamp": "2019-06-24T20:46:30.134Z", "Id": "55d0052b-0d7d-44d6-b56f-21867215e118", "Version": "33f709a0-c825-49cb-9eea-dc8964fbd635" }

下列程式碼範例會示範如何使用create-connector-definition

AWS CLI

建立連接器定義的步驟

下列create-connector-definition範例範例會建立連接器定義和初始連接器定義版本。初始版本包含一個連接器。版本中的所有連接器都會定義其參數的值。

aws greengrass create-connector-definition \ --name MySNSConnector \ --initial-version "{\"Connectors\": [{\"Id\":\"MySNSConnector\",\"ConnectorArn\":\"arn:aws:greengrass:us-west-2::/connectors/SNS/versions/1\",\"Parameters\": {\"DefaultSNSArn\":\"arn:aws:sns:us-west-2:123456789012:GGConnectorTopic\"}}]}"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "CreationTimestamp": "2019-06-19T19:30:01.300Z", "Id": "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "LastUpdatedTimestamp": "2019-06-19T19:30:01.300Z", "LatestVersion": "63c57963-c7c2-4a26-a7e2-7bf478ea2623", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8/versions/63c57963-c7c2-4a26-a7e2-7bf478ea2623", "Name": "MySNSConnector" }

如需詳細資訊,請參AWS IoT Greengrass 開發人員指南中的 Greengrass 連接器入門 (CLI)

下列程式碼範例會示範如何使用create-core-definition-version

AWS CLI

若要建立核心定義版本

下列create-core-definition-version範例會建立核心定義版本,並將其與指定的核心定義產生關聯。該版本只能包含一個核心。您必須先建立並佈建對應的 AWS IoT 物件,才能建立核心。此程序包含下列iot指令,這些指令會傳回指create-core-definition-versionCertificateArn所需的ThingArn和。

建立與核心裝置對應的 AWS IoT 物件:

aws iot create-thing \ --thing-name "MyCoreDevice"

輸出:

{ "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyCoreDevice", "thingName": "MyCoreDevice", "thingId": "cb419a19-9099-4515-9cec-e9b0e760608a" }

建立物件的公開金鑰和私密金鑰以及核心裝置憑證。此範例使用命create-keys-and-certificate令並需要目前目錄的寫入權限。或者,您可以使用create-certificate-from-csr指令。

aws iot create-keys-and-certificate \ --set-as-active \ --certificate-pem-outfile "myCore.cert.pem" \ --public-key-outfile "myCore.public.key" \ --private-key-outfile "myCore.private.key"

輸出:

{ "certificateArn": "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz", "certificatePem": "-----BEGIN CERTIFICATE-----\nMIIDWTCAkGgAwIBATgIUCgq6EGqou6zFqWgIZRndgQEFW+gwDQYJKoZIhvc...KdGewQS\n-----END CERTIFICATE-----\n", "keyPair": { "PublicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBzrqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKpRgnn6yq26U3y...wIDAQAB\n-----END PUBLIC KEY-----\n", "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIABAKCAQEAqKpRgnn6yq26U3yt5YFZquyukfRjbMXDcNOK4rMCxDR...fvY4+te\n-----END RSA PRIVATE KEY-----\n" }, "certificateId": "123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz" }

建立允許iotgreengrass動作的 AWS IoT 原則。為了簡單起見,下列原則允許對所有資源執行動作,但您的政策應該更具限制性。

aws iot create-policy \ --policy-name "Core_Devices" \ --policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}"

輸出:

{ "policyName": "Core_Devices", "policyArn": "arn:aws:iot:us-west-2:123456789012:policy/Core_Devices", "policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}", "policyVersionId": "1" }

將原則附加至憑證:

aws iot attach-policy \ --policy-name "Core_Devices" \ --target "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz"

此命令不會產生輸出。

將東西附加到證書上:

aws iot attach-thing-principal \ --thing-name "MyCoreDevice" \ --principal "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz"

此命令不會產生輸出。

建立核心定義版本:

aws greengrass create-core-definition-version \ --core-definition-id "582efe12-b05a-409e-9a24-a2ba1bcc4a12" \ --cores "[{\"Id\":\"MyCoreDevice\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/MyCoreDevice\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz\",\"SyncShadow\":true}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/582efe12-b05a-409e-9a24-a2ba1bcc4a12/versions/3fdc1190-2ce5-44de-b98b-eec8f9571014", "Version": "3fdc1190-2ce5-44de-b98b-eec8f9571014", "CreationTimestamp": "2019-09-18T00:15:09.838Z", "Id": "582efe12-b05a-409e-9a24-a2ba1bcc4a12" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定 AWS IoT Gre engrass 核心

下列程式碼範例會示範如何使用create-core-definition

AWS CLI

範例 1:若要建立空的核心定義

下面的create-core-definition例子創建一個空的(沒有初始版本)Greengrass 核心定義。在核心可用之前,您必須使用create-core-definition-version指令來提供核心的其他參數。

aws greengrass create-core-definition \ --name cliGroup_Core

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/b5c08008-54cb-44bd-9eec-c121b04283b5", "CreationTimestamp": "2019-06-25T18:23:22.106Z", "Id": "b5c08008-54cb-44bd-9eec-c121b04283b5", "LastUpdatedTimestamp": "2019-06-25T18:23:22.106Z", "Name": "cliGroup_Core" }

範例 2:使用初始版本建立核心定義

下列create-core-definition範例會建立包含初始核心定義版本的核心定義。該版本只能包含一個核心。您必須先建立並佈建對應的 AWS IoT 物件,才能建立核心。此程序包含下列iot指令,這些指令會傳回指create-core-definitionCertificateArn所需的ThingArn和。

建立與核心裝置對應的 AWS IoT 物件:

aws iot create-thing \ --thing-name "MyCoreDevice"

輸出:

{ "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyCoreDevice", "thingName": "MyCoreDevice", "thingId": "cb419a19-9099-4515-9cec-e9b0e760608a" }

建立物件的公開金鑰和私密金鑰以及核心裝置憑證。此範例使用命create-keys-and-certificate令並需要目前目錄的寫入權限。或者,您可以使用create-certificate-from-csr指令。

aws iot create-keys-and-certificate \ --set-as-active \ --certificate-pem-outfile "myCore.cert.pem" \ --public-key-outfile "myCore.public.key" \ --private-key-outfile "myCore.private.key"

輸出:

{ "certificateArn": "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz", "certificatePem": "-----BEGIN CERTIFICATE-----\nMIIDWTCAkGgAwIBATgIUCgq6EGqou6zFqWgIZRndgQEFW+gwDQYJKoZIhvc...KdGewQS\n-----END CERTIFICATE-----\n", "keyPair": { "PublicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBzrqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKpRgnn6yq26U3y...wIDAQAB\n-----END PUBLIC KEY-----\n", "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIABAKCAQEAqKpRgnn6yq26U3yt5YFZquyukfRjbMXDcNOK4rMCxDR...fvY4+te\n-----END RSA PRIVATE KEY-----\n" }, "certificateId": "123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz" }

建立允許iotgreengrass動作的 AWS IoT 原則。為了簡單起見,下列原則允許對所有資源執行動作,但您的政策應該更具限制性。

aws iot create-policy \ --policy-name "Core_Devices" \ --policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}"

輸出:

{ "policyName": "Core_Devices", "policyArn": "arn:aws:iot:us-west-2:123456789012:policy/Core_Devices", "policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}", "policyVersionId": "1" }

將原則附加至憑證:

aws iot attach-policy \ --policy-name "Core_Devices" \ --target "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz"

此命令不會產生輸出。

將東西附加到證書上:

aws iot attach-thing-principal \ --thing-name "MyCoreDevice" \ --principal "arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz"

此命令不會產生輸出。

建立核心定義:

aws greengrass create-core-definition \ --name "MyCores" \ --initial-version "{\"Cores\":[{\"Id\":\"MyCoreDevice\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/MyCoreDevice\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/123a15ec415668c2349a76170b64ac0878231c1e21ec83c10e92a1EXAMPLExyz\",\"SyncShadow\":true}]}"

輸出:

{ "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/582efe12-b05a-409e-9a24-a2ba1bcc4a12/versions/cc87b5b3-8f4b-465d-944c-1d6de5dbfcdb", "Name": "MyCores", "LastUpdatedTimestamp": "2019-09-18T00:11:06.197Z", "LatestVersion": "cc87b5b3-8f4b-465d-944c-1d6de5dbfcdb", "CreationTimestamp": "2019-09-18T00:11:06.197Z", "Id": "582efe12-b05a-409e-9a24-a2ba1bcc4a12", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/582efe12-b05a-409e-9a24-a2ba1bcc4a12" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定 AWS IoT Gre engrass 核心

下列程式碼範例會示範如何使用create-deployment

AWS CLI

若要為 Greengrass 群組的版本建立部署

下列create-deployment範例會部署 Greengrass 群組的指定版本。

aws greengrass create-deployment \ --deployment-type NewDeployment \ --group-id "ce2e7d01-3240-4c24-b8e6-f6f6e7a9eeca" \ --group-version-id "dc40c1e9-e8c8-4d28-a84d-a9cad5f599c9"

輸出:

{ "DeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/ce2e7d01-3240-4c24-b8e6-f6f6e7a9eeca/deployments/bfceb608-4e97-45bc-af5c-460144270308", "DeploymentId": "bfceb608-4e97-45bc-af5c-460144270308" }

如需詳細資訊,請參AWS IoT Greengrass 開發人員指南中的連接器入門 (CLI)

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

下列程式碼範例會示範如何使用create-device-definition-version

AWS CLI

建立裝置定義版本

下列create-device-definition-version範例會建立裝置定義版本,並將其與指定的裝置定義產生關聯。該版本定義了兩個設備。您必須先建立並佈建對應 AWS 的 IoT 物件,才能建立 Greengrass 裝置。此程序包含下列iot命令,您必須執行這些命令才能取得 Greengrass 命令的必要資訊:

建立與裝置對應的 AWS IoT 物件:

aws iot create-thing \ --thing-name "InteriorTherm"

輸出:

{ "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/InteriorTherm", "thingName": "InteriorTherm", "thingId": "01d4763c-78a6-46c6-92be-7add080394bf" }

建立物件的公開金鑰和私密金鑰以及裝置憑證。此範例使用命create-keys-and-certificate令並需要目前目錄的寫入權限。或者,您可以使用以下create-certificate-from-csr命令:

aws iot create-keys-and-certificate \ --set-as-active \ --certificate-pem-outfile "myDevice.cert.pem" \ --public-key-outfile "myDevice.public.key" \ --private-key-outfile "myDevice.private.key"

輸出:

{ "certificateArn": "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92", "certificatePem": "-----BEGIN CERTIFICATE-----\nMIIDWTCAkGgAwIBATgIUCgq6EGqou6zFqWgIZRndgQEFW+gwDQYJKoZIhvc...KdGewQS\n-----END CERTIFICATE-----\n", "keyPair": { "PublicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBzrqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKpRgnn6yq26U3y...wIDAQAB\n-----END PUBLIC KEY-----\n", "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIABAKCAQEAqKpRgnn6yq26U3yt5YFZquyukfRjbMXDcNOK4rMCxDR...fvY4+te\n-----END RSA PRIVATE KEY-----\n" }, "certificateId": "66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92" }

建立允許iotgreengrass動作的 AWS IoT 原則。為了簡單起見,下列原則允許對所有資源執行動作,但是您的政策可能會更具限制性:

aws iot create-policy \ --policy-name "GG_Devices" \ --policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}"

輸出:

{ "policyName": "GG_Devices", "policyArn": "arn:aws:iot:us-west-2:123456789012:policy/GG_Devices", "policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}", "policyVersionId": "1" }

將原則附加至憑證:

aws iot attach-policy \ --policy-name "GG_Devices" \ --target "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92"

將東西附加到證書

aws iot attach-thing-principal \ --thing-name "InteriorTherm" \ --principal "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92"

如上所示建立並設定 IoT 物件之後,請使用下ThingArn列範例中前兩個命令的 and。CertificateArn

aws greengrass create-device-definition-version \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd" \ --devices "[{\"Id\":\"InteriorTherm\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/InteriorTherm\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92\",\"SyncShadow\":true},{\"Id\":\"ExteriorTherm\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/ExteriorTherm\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/6c52ce1b47bde88a637e9ccdd45fe4e4c2c0a75a6866f8f63d980ee22fa51e02\",\"SyncShadow\":true}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/83c13984-6fed-447e-84d5-5b8aa45d5f71", "Version": "83c13984-6fed-447e-84d5-5b8aa45d5f71", "CreationTimestamp": "2019-09-11T00:15:09.838Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd" }

下列程式碼範例會示範如何使用create-device-definition

AWS CLI

建立裝置定義

下列create-device-definition範例會建立包含初始裝置定義版本的裝置定義。初始版本定義了兩個設備。您必須先建立並佈建對應 AWS 的 IoT 物件,才能建立 Greengrass 裝置。此程序包含下列iot命令,您必須執行這些命令才能取得 Greengrass 命令的必要資訊:

建立與裝置對應的 AWS IoT 物件:

aws iot create-thing \ --thing-name "InteriorTherm"

輸出:

{ "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/InteriorTherm", "thingName": "InteriorTherm", "thingId": "01d4763c-78a6-46c6-92be-7add080394bf" }

建立物件的公開金鑰和私密金鑰以及裝置憑證。此範例使用命create-keys-and-certificate令並需要目前目錄的寫入權限。或者,您可以使用以下create-certificate-from-csr命令:

aws iot create-keys-and-certificate \ --set-as-active \ --certificate-pem-outfile "myDevice.cert.pem" \ --public-key-outfile "myDevice.public.key" \ --private-key-outfile "myDevice.private.key"

輸出:

{ "certificateArn": "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92", "certificatePem": "-----BEGIN CERTIFICATE-----\nMIIDWTCAkGgAwIBATgIUCgq6EGqou6zFqWgIZRndgQEFW+gwDQYJKoZIhvc...KdGewQS\n-----END CERTIFICATE-----\n", "keyPair": { "PublicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBzrqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKpRgnn6yq26U3y...wIDAQAB\n-----END PUBLIC KEY-----\n", "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIABAKCAQEAqKpRgnn6yq26U3yt5YFZquyukfRjbMXDcNOK4rMCxDR...fvY4+te\n-----END RSA PRIVATE KEY-----\n" }, "certificateId": "66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92" }

建立允許iotgreengrass動作的 AWS IoT 原則。為了簡單起見,下列原則允許對所有資源執行動作,但是您的政策可能會更具限制性:

aws iot create-policy \ --policy-name "GG_Devices" \ --policy-document "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}"

輸出:

{ "policyName": "GG_Devices", "policyArn": "arn:aws:iot:us-west-2:123456789012:policy/GG_Devices", "policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Publish\",\"iot:Subscribe\",\"iot:Connect\",\"iot:Receive\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"iot:GetThingShadow\",\"iot:UpdateThingShadow\",\"iot:DeleteThingShadow\"],\"Resource\":[\"*\"]},{\"Effect\":\"Allow\",\"Action\":[\"greengrass:*\"],\"Resource\":[\"*\"]}]}", "policyVersionId": "1" }

將原則附加至憑證:

aws iot attach-policy \ --policy-name "GG_Devices" \ --target "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92"

將東西附加到證書

aws iot attach-thing-principal \ --thing-name "InteriorTherm" \ --principal "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92"

如上所示建立並設定 IoT 物件之後,請使用下ThingArn列範例中前兩個命令的 and。CertificateArn

aws greengrass create-device-definition \ --name "Sensors" \ --initial-version "{\"Devices\":[{\"Id\":\"InteriorTherm\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/InteriorTherm\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92\",\"SyncShadow\":true},{\"Id\":\"ExteriorTherm\",\"ThingArn\":\"arn:aws:iot:us-west-2:123456789012:thing/ExteriorTherm\",\"CertificateArn\":\"arn:aws:iot:us-west-2:123456789012:cert/6c52ce1b47bde88a637e9ccdd45fe4e4c2c0a75a6866f8f63d980ee22fa51e02\",\"SyncShadow\":true}]}"

輸出:

{ "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/3b5cc510-58c1-44b5-9d98-4ad858ffa795", "Name": "Sensors", "LastUpdatedTimestamp": "2019-09-11T00:11:06.197Z", "LatestVersion": "3b5cc510-58c1-44b5-9d98-4ad858ffa795", "CreationTimestamp": "2019-09-11T00:11:06.197Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd" }

下列程式碼範例會示範如何使用create-function-definition-version

AWS CLI

若要建立函數定義的版本

下列create-function-definition-version範例會建立指定函數定義的新版本。此版本指定一個函數,其 ID 是Hello-World-function,允許訪問文件系統,並指定最大內存大小和超時期限。

aws greengrass create-function-definition-version \ --cli-input-json "{\"FunctionDefinitionId\": \"e626e8c9-3b8f-4bf3-9cdc-d26ecdeb9fa3\",\"Functions\": [{\"Id\": \"Hello-World-function\", \"FunctionArn\": \""arn:aws:lambda:us-west-2:123456789012:function:Greengrass_HelloWorld_Counter:gghw-alias"\",\"FunctionConfiguration\": {\"Environment\": {\"AccessSysfs\": true},\"Executable\": \"greengrassHelloWorldCounter.function_handler\",\"MemorySize\": 16000,\"Pinned\": false,\"Timeout\": 25}}]}"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/e626e8c9-3b8f-4bf3-9cdc-d26ecdeb9fa3/versions/74abd1cc-637e-4abe-8684-9a67890f4043", "CreationTimestamp": "2019-06-25T22:03:43.376Z", "Id": "e626e8c9-3b8f-4bf3-9cdc-d26ecdeb9fa3", "Version": "74abd1cc-637e-4abe-8684-9a67890f4043" }

下列程式碼範例會示範如何使用create-function-definition

AWS CLI

若要建立 Lambda 函數定義

下列create-function-definition範例會提供 Lambda 函數清單 (在本例中,只有一個名為函數的清單TempMonitorFunction) 及其組態,建立 Lambda 函數定義和初始版本。在您可以建立函數定義之前,您需要 Lambda 函數 ARN。若要建立函數及其別名,請使用 Lambda 的create-functionpublish-version指令。Lambda 的create-function命令需要執行角色的 ARN,即使 AWS IoT Greengrass 不使用該角色,因為許可是在 Greengrass 群組角色中指定的。您可以使用 IAM create-role 命令建立空白角色,以取得要與 Lambda 搭配使用的 ARN,create-function也可以使用現有的執行角色。

aws greengrass create-function-definition \ --name MyGreengrassFunctions \ --initial-version "{\"Functions\": [{\"Id\": \"TempMonitorFunction\", \"FunctionArn\": \"arn:aws:lambda:us-west-2:123456789012:function:TempMonitor:GG_TempMonitor\", \"FunctionConfiguration\": {\"Executable\": \"temp_monitor.function_handler\", \"MemorySize\": 16000,\"Timeout\": 5}}]}"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/3b0d0080-87e7-48c6-b182-503ec743a08b", "CreationTimestamp": "2019-06-19T22:24:44.585Z", "Id": "3b0d0080-87e7-48c6-b182-503ec743a08b", "LastUpdatedTimestamp": "2019-06-19T22:24:44.585Z", "LatestVersion": "67f918b9-efb4-40b0-b87c-de8c9faf085b", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/3b0d0080-87e7-48c6-b182-503ec743a08b/versions/67f918b9-efb4-40b0-b87c-de8c9faf085b", "Name": "MyGreengrassFunctions" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的如何使用 AWS 命令列介面設定本機資源存取

下列程式碼範例會示範如何使用create-group-certificate-authority

AWS CLI

建立群組的憑證授權單位 (CA)

下列create-group-certificate-authority範例會建立或旋轉指定群組的 CA。

aws greengrass create-group-certificate-authority \ --group-id "8eaadd72-ce4b-4f15-892a-0cc4f3a343f1"

輸出:

{ "GroupCertificateAuthorityArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/8eaadd72-ce4b-4f15-892a-0cc4f3a343f1/certificateauthorities/d31630d674c4437f6c5dbc0dca56312a902171ce2d086c38e509c8EXAMPLEcc5" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的 AWS IoT 網路安全性

下列程式碼範例會示範如何使用create-group-version

AWS CLI

若要建立 Greengrass 色群組的版本

下列create-group-version範例會建立群組版本,並將其與指定的群組產生關聯。版本會參考核心、資源、連接器、函數和訂閱版本,這些版本包含要包含在此群組版本中的實體。您必須先建立這些實體,才能建立群組版本。

若要使用初始版本建立連接器定義,create-resource-definition請使用指令建立具有初始版本的函數定義create-connector-definition。若要使用初始版本建立訂閱定義,請使用指create-function-definition令。若要擷取最新核心定義版本的 ARN,請使用get-group-version指令並指定最新群組版本的 ID create-subscription-definition

aws greengrass create-group-version \ --group-id "ce2e7d01-3240-4c24-b8e6-f6f6e7a9eeca" \ --core-definition-version-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/6a630442-8708-4838-ad36-eb98849d975e/versions/6c87151b-1fb4-4cb2-8b31-6ee715d8f8ba" \ --resource-definition-version-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38/versions/a5f94d0b-f6bc-40f4-bb78-7a1c5fe13ba1" \ --connector-definition-version-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/55d0052b-0d7d-44d6-b56f-21867215e118/versions/78a3331b-895d-489b-8823-17b4f9f418a0" \ --function-definition-version-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/3b0d0080-87e7-48c6-b182-503ec743a08b/versions/67f918b9-efb4-40b0-b87c-de8c9faf085b" \ --subscription-definition-version-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/9d611d57-5d5d-44bd-a3b4-feccbdd69112/versions/aa645c47-ac90-420d-9091-8c7ffa4f103f"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/ce2e7d01-3240-4c24-b8e6-f6f6e7a9eeca/versions/e10b0459-4345-4a09-88a4-1af1f5d34638", "CreationTimestamp": "2019-06-20T18:42:47.020Z", "Id": "ce2e7d01-3240-4c24-b8e6-f6f6e7a9eeca", "Version": "e10b0459-4345-4a09-88a4-1af1f5d34638" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的 IoT Greengrass 群組物件模型概觀。AWS

下列程式碼範例會示範如何使用create-group

AWS CLI

若要建立希臘群組

下列create-group範例會建立名為的群組cli-created-group

aws greengrass create-group \ --name cli-created-group

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/4e22bd92-898c-436b-ade5-434d883ff749", "CreationTimestamp": "2019-06-25T18:07:17.688Z", "Id": "4e22bd92-898c-436b-ade5-434d883ff749", "LastUpdatedTimestamp": "2019-06-25T18:07:17.688Z", "Name": "cli-created-group" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的 IoT Greengrass 群組物件模型概觀。AWS

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

下列程式碼範例會示範如何使用create-logger-definition-version

AWS CLI

若要建立記錄器定義版本

下列create-logger-definition-version範例會建立記錄器定義版本,並將其與記錄器定義相關聯。該版本定義了四個記錄組態:1) 核心裝置檔案系統上的系統元件日誌、2) 核心裝置檔案系統上的使用者定義 Lambda 函數日誌、3) Amazon 日誌中的系統元件日誌,以及 4) Amazon CloudWatch 日誌中使用者定義的 Lambda 函數 CloudWatch 日誌。附註:若要進行 CloudWatch 記錄整合,您的群組角色必須授與適當的權限。

aws greengrass create-logger-definition-version \ --logger-definition-id "a454b62a-5d56-4ca9-bdc4-8254e1662cb0" \ --loggers "[{\"Id\":\"1\",\"Component\":\"GreengrassSystem\",\"Level\":\"ERROR\",\"Space\":10240,\"Type\":\"FileSystem\"},{\"Id\":\"2\",\"Component\":\"Lambda\",\"Level\":\"INFO\",\"Space\":10240,\"Type\":\"FileSystem\"},{\"Id\":\"3\",\"Component\":\"GreengrassSystem\",\"Level\":\"WARN\",\"Type\":\"AWSCloudWatch\"},{\"Id\":\"4\",\"Component\":\"Lambda\",\"Level\":\"INFO\",\"Type\":\"AWSCloudWatch\"}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/a454b62a-5d56-4ca9-bdc4-8254e1662cb0/versions/49aedb1e-01a3-4d39-9871-3a052573f1ea", "Version": "49aedb1e-01a3-4d39-9871-3a052573f1ea", "CreationTimestamp": "2019-07-24T00:04:48.523Z", "Id": "a454b62a-5d56-4ca9-bdc4-8254e1662cb0" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指AWS 南中的使用 IoT Greengrass 記錄進行監視

下列程式碼範例會示範如何使用create-logger-definition

AWS CLI

若要建立記錄器定義

下列create-logger-definition範例會建立包含初始記錄器定義版本的記錄器定義。初始版本定義了三個記錄組態:1) 核心裝置檔案系統上的系統元件日誌、2) 核心裝置檔案系統上的使用者定義 Lambda 函數日誌,以及 3) Amazon 日誌中使用者定義的 Lambda 函數 CloudWatch 日誌。附註:若要進行 CloudWatch 記錄整合,您的群組角色必須授與適當的權限。

aws greengrass create-logger-definition \ --name "LoggingConfigs" \ --initial-version "{\"Loggers\":[{\"Id\":\"1\",\"Component\":\"GreengrassSystem\",\"Level\":\"ERROR\",\"Space\":10240,\"Type\":\"FileSystem\"},{\"Id\":\"2\",\"Component\":\"Lambda\",\"Level\":\"INFO\",\"Space\":10240,\"Type\":\"FileSystem\"},{\"Id\":\"3\",\"Component\":\"Lambda\",\"Level\":\"INFO\",\"Type\":\"AWSCloudWatch\"}]}"

輸出:

{ "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/a454b62a-5d56-4ca9-bdc4-8254e1662cb0/versions/de1d9854-1588-4525-b25e-b378f60f2322", "Name": "LoggingConfigs", "LastUpdatedTimestamp": "2019-07-23T23:52:17.165Z", "LatestVersion": "de1d9854-1588-4525-b25e-b378f60f2322", "CreationTimestamp": "2019-07-23T23:52:17.165Z", "Id": "a454b62a-5d56-4ca9-bdc4-8254e1662cb0", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/a454b62a-5d56-4ca9-bdc4-8254e1662cb0" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指AWS 南中的使用 IoT Greengrass 記錄進行監視

下列程式碼範例會示範如何使用create-resource-definition-version

AWS CLI

若要建立資源定義的版本

下列create-resource-definition-version範例會建立新版本的 TwilioAuthToken.

aws greengrass create-resource-definition-version \ --resource-definition-id "c8bb9ebc-c3fd-40a4-9c6a-568d75569d38" \ --resources "[{\"Id\": \"TwilioAuthToken\",\"Name\": \"MyTwilioAuthToken\",\"ResourceDataContainer\": {\"SecretsManagerSecretResourceData\": {\"ARN\": \"arn:aws:secretsmanager:us-west-2:123456789012:secret:greengrass-TwilioAuthToken-ntSlp6\"}}}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38/versions/b3bcada0-5fb6-42df-bf0b-1ee4f15e769e", "CreationTimestamp": "2019-06-24T21:17:25.623Z", "Id": "c8bb9ebc-c3fd-40a4-9c6a-568d75569d38", "Version": "b3bcada0-5fb6-42df-bf0b-1ee4f15e769e" }

下列程式碼範例會示範如何使用create-resource-definition

AWS CLI

建立資源定義的步驟

下列create-resource-definition範例會建立資源定義,其中包含要在 Greengrass 群組中使用的資源清單。在此範例中,透過提供資源清單來包含資源定義的初始版本。該列表包括 Twilio 授權令牌的一個資源和 ARN 用於存儲在秘密管理器中 AWS 的秘密。您必須先建立密碼,才能建立資源定義。

aws greengrass create-resource-definition \ --name MyGreengrassResources \ --initial-version "{\"Resources\": [{\"Id\": \"TwilioAuthToken\",\"Name\": \"MyTwilioAuthToken\",\"ResourceDataContainer\": {\"SecretsManagerSecretResourceData\": {\"ARN\": \"arn:aws:secretsmanager:us-west-2:123456789012:secret:greengrass-TwilioAuthToken-ntSlp6\"}}}]}"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38", "CreationTimestamp": "2019-06-19T21:51:28.212Z", "Id": "c8bb9ebc-c3fd-40a4-9c6a-568d75569d38", "LastUpdatedTimestamp": "2019-06-19T21:51:28.212Z", "LatestVersion": "a5f94d0b-f6bc-40f4-bb78-7a1c5fe13ba1", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38/versions/a5f94d0b-f6bc-40f4-bb78-7a1c5fe13ba1", "Name": "MyGreengrassResources" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的如何使用 AWS 命令列介面設定本機資源存取

下列程式碼範例會示範如何使用create-software-update-job

AWS CLI

若要建立核心的軟體更新工作

下列create-software-update-job範例會建立 over-the-air (OTA) 更新工作,以更新名稱為的核心上的 AWS IoT Greengrass 核心軟體。MyFirstGroup_Core此命令需要 IAM 角色,該角色允許存取 Amazon S3 中的軟體更新套件,並包含iot.amazonaws.com為受信任的實體。

aws greengrass create-software-update-job \ --update-targets-architecture armv7l \ --update-targets [\"arn:aws:iot:us-west-2:123456789012:thing/MyFirstGroup_Core\"] \ --update-targets-operating-system raspbian \ --software-to-update core \ --s3-url-signer-role arn:aws:iam::123456789012:role/OTA_signer_role \ --update-agent-log-level WARN

輸出:

{ "IotJobId": "GreengrassUpdateJob_30b353e3-3af7-4786-be25-4c446663c09e", "IotJobArn": "arn:aws:iot:us-west-2:123456789012:job/GreengrassUpdateJob_30b353e3-3af7-4786-be25-4c446663c09e", "PlatformSoftwareVersion": "1.9.3" }

如需詳細資訊,請參閱 IoT Greengrass 開發人員指南中的 AWS IoT Greengrass 核心軟體的AWS OTA 更新。

下列程式碼範例會示範如何使用create-subscription-definition-version

AWS CLI

若要建立訂閱定義的新版本

下列create-subscription-definition-version範例會建立包含三個訂閱的新版訂閱定義:觸發器通知、溫度輸入和輸出狀態。

aws greengrass create-subscription-definition-version \ --subscription-definition-id "9d611d57-5d5d-44bd-a3b4-feccbdd69112" \ --subscriptions "[{\"Id\": \"TriggerNotification\", \"Source\": \"arn:aws:lambda:us-west-2:123456789012:function:TempMonitor:GG_TempMonitor\", \"Subject\": \"twilio/txt\", \"Target\": \"arn:aws:greengrass:us-west-2::/connectors/TwilioNotifications/versions/1\"},{\"Id\": \"TemperatureInput\", \"Source\": \"cloud\", \"Subject\": \"temperature/input\", \"Target\": \"arn:aws:lambda:us-west-2:123456789012:function:TempMonitor:GG_TempMonitor\"},{\"Id\": \"OutputStatus\", \"Source\": \"arn:aws:greengrass:us-west-2::/connectors/TwilioNotifications/versions/1\", \"Subject\": \"twilio/message/status\", \"Target\": \"cloud\"}]"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/9d611d57-5d5d-44bd-a3b4-feccbdd69112/versions/7b65dfae-50b6-4d0f-b3e0-27728bfb0620", "CreationTimestamp": "2019-06-24T21:21:33.837Z", "Id": "9d611d57-5d5d-44bd-a3b4-feccbdd69112", "Version": "7b65dfae-50b6-4d0f-b3e0-27728bfb0620" }

下列程式碼範例會示範如何使用create-subscription-definition

AWS CLI

若要建立訂閱定義

下列create-subscription-definition範例會建立訂閱定義並指定其初始版本。初始版本包含三個訂閱:一個用於連接器訂閱的 MQTT 主題,一個用於允許從 IoT 接收溫度讀數的函數,另一個用於允許 AWS AWS IoT 從連接器接收狀態資訊。此範例會針對先前使用 Lambda 的create-alias命令建立的 Lambda 函數別名提供 ARN。

aws greengrass create-subscription-definition \ --initial-version "{\"Subscriptions\": [{\"Id\": \"TriggerNotification\", \"Source\": \"arn:aws:lambda:us-west-2:123456789012:function:TempMonitor:GG_TempMonitor\", \"Subject\": \"twilio/txt\", \"Target\": \"arn:aws:greengrass:us-west-2::/connectors/TwilioNotifications/versions/1\"},{\"Id\": \"TemperatureInput\", \"Source\": \"cloud\", \"Subject\": \"temperature/input\", \"Target\": \"arn:aws:lambda:us-west-2:123456789012:function:TempMonitor:GG_TempMonitor\"},{\"Id\": \"OutputStatus\", \"Source\": \"arn:aws:greengrass:us-west-2::/connectors/TwilioNotifications/versions/1\", \"Subject\": \"twilio/message/status\", \"Target\": \"cloud\"}]}"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/9d611d57-5d5d-44bd-a3b4-feccbdd69112", "CreationTimestamp": "2019-06-19T22:34:26.677Z", "Id": "9d611d57-5d5d-44bd-a3b4-feccbdd69112", "LastUpdatedTimestamp": "2019-06-19T22:34:26.677Z", "LatestVersion": "aa645c47-ac90-420d-9091-8c7ffa4f103f", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/9d611d57-5d5d-44bd-a3b4-feccbdd69112/versions/aa645c47-ac90-420d-9091-8c7ffa4f103f" }

如需詳細資訊,請參AWS IoT Greengrass 開發人員指南中的連接器入門 (CLI)

下列程式碼範例會示範如何使用delete-connector-definition

AWS CLI

刪除連接器定義的步驟

下列delete-connector-definition範例會刪除指定的 Greengrass 連接器定義。如果您刪除群組使用的連接器定義,則無法成功部署該群組。

aws greengrass delete-connector-definition \ --connector-definition-id "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8"

此命令不會產生輸出。

下列程式碼範例會示範如何使用delete-core-definition

AWS CLI

若要刪除核心定義

下列delete-core-definition範例會刪除指定的 Greengrass 核心定義,包括所有版本。如果您刪除與 Greengrass 群組相關聯的核心,則無法成功部署該群組。

aws greengrass delete-core-definition \ --core-definition-id "ff36cc5f-9f98-4994-b468-9d9b6dc52abd"

此命令不會產生輸出。

下列程式碼範例會示範如何使用delete-device-definition

AWS CLI

刪除裝置定義

下列delete-device-definition範例會刪除指定的裝置定義,包括其所有版本。如果您刪除群組版本所使用的裝置定義版本,則無法成功部署群組版本。

aws greengrass delete-device-definition \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd"

此命令不會產生輸出。

下列程式碼範例會示範如何使用delete-function-definition

AWS CLI

刪除函數定義的步驟

下列delete-function-definition範例會刪除指定的 Greengrass 函數定義。如果您刪除群組使用的函數定義,則無法成功部署該群組。

aws greengrass delete-function-definition \ --function-definition-id "fd4b906a-dff3-4c1b-96eb-52ebfcfac06a"

此命令不會產生輸出。

下列程式碼範例會示範如何使用delete-group

AWS CLI

若要刪除群組

下列delete-group範例會刪除指定的 Greengrass 群組。

aws greengrass delete-group \ --group-id "4e22bd92-898c-436b-ade5-434d883ff749"

此命令不會產生輸出。

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

下列程式碼範例會示範如何使用delete-logger-definition

AWS CLI

若要刪除記錄器定義

下列delete-logger-definition範例會刪除指定的記錄器定義,包括所有記錄器定義版本。如果您刪除群組版本所使用的記錄器定義版本,則無法成功部署群組版本。

aws greengrass delete-logger-definition \ --logger-definition-id "a454b62a-5d56-4ca9-bdc4-8254e1662cb0"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指AWS 南中的使用 IoT Greengrass 記錄進行監視

下列程式碼範例會示範如何使用delete-resource-definition

AWS CLI

若要刪除資源定義

下列delete-resource-definition範例會刪除指定的資源定義,包括所有資源版本。如果您刪除群組使用的資源定義,則無法成功部署該群組。

aws greengrass delete-resource-definition \ --resource-definition-id "ad8c101d-8109-4b0e-b97d-9cc5802ab658"

此命令不會產生輸出。

下列程式碼範例會示範如何使用delete-subscription-definition

AWS CLI

若要刪除訂閱定義

下列delete-subscription-definition範例會刪除指定的 Greengrass 訂閱定義。如果您刪除群組正在使用的訂閱,則無法成功部署該群組。

aws greengrass delete-subscription-definition \ --subscription-definition-id "cd6f1c37-d9a4-4e90-be94-01a7404f5967"

此命令不會產生輸出。

下列程式碼範例會示範如何使用disassociate-role-from-group

AWS CLI

若要取消角色與 Greengrass 群組的關聯

下列disassociate-role-from-group範例會取消 IAM 角色與指定之 Greengrass 群組的關聯性。

aws greengrass disassociate-role-from-group \ --group-id 2494ee3f-7f8a-4e92-a78b-d205f808b84b

輸出:

{ "DisassociatedAt": "2019-09-10T20:05:49Z" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定群組角色

下列程式碼範例會示範如何使用disassociate-service-role-from-account

AWS CLI

取消服務角色與帳戶的 AWS 關聯

下列disassociate-service-role-from-account範例會移除與您 AWS 帳戶相關聯的服務角色。如果您未在任何 AWS 區域中使用服務角色,請使用delete-role-policy命令將AWSGreengrassResourceAccessRolePolicy受管理的策略與角色中斷連結,然後使用delete-role命令刪除角色。

aws greengrass disassociate-service-role-from-account

輸出:

{ "DisassociatedAt": "2019-06-25T22:12:55Z" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的《Gre engrass 服務角色》。

下列程式碼範例會示範如何使用get-associated-role

AWS CLI

若要取得與 Greengrass 群組相關聯的角色

下列get-associated-role範例會取得與指定之 Greengrass 群組相關聯的 IAM 角色。本機 Lambda 函數和連接器會使用群組角色來存取 AWS 服務。

aws greengrass get-associated-role \ --group-id 2494ee3f-7f8a-4e92-a78b-d205f808b84b

輸出:

{ "RoleArn": "arn:aws:iam::123456789012:role/GG-Group-Role", "AssociatedAt": "2019-09-10T20:03:30Z" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定群組角色

下列程式碼範例會示範如何使用get-bulk-deployment-status

AWS CLI

若要檢查大量部署的狀態

下列get-bulk-deployment-status範例會擷取指定大量部署作業的狀態資訊。在此範例中,指定要部署之群組的檔案具有無效的輸入記錄。

aws greengrass get-bulk-deployment-status \ --bulk-deployment-id "870fb41b-6288-4e0c-bc76-a7ba4b4d3267"

輸出:

{ "BulkDeploymentMetrics": { "InvalidInputRecords": 1, "RecordsProcessed": 1, "RetryAttempts": 0 }, "BulkDeploymentStatus": "Completed", "CreatedAt": "2019-06-25T16:11:33.265Z", "tags": {} }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的為群組建立大量部署

下列程式碼範例會示範如何使用get-connectivity-info

AWS CLI

若要取得 Greengrass 核心的連線資訊

下列get-connectivity-info範例顯示裝置可用來連線至指定之 Greengrass 核心的端點。連線資訊是 IP 位址或網域名稱的清單,以及對應的連接埠號碼和選用的客戶定義的中繼資料。

aws greengrass get-connectivity-info \ --thing-name "MyGroup_Core"

輸出:

{ "ConnectivityInfo": [ { "Metadata": "", "PortNumber": 8883, "HostAddress": "127.0.0.1", "Id": "AUTOIP_127.0.0.1_0" }, { "Metadata": "", "PortNumber": 8883, "HostAddress": "192.168.1.3", "Id": "AUTOIP_192.168.1.3_1" }, { "Metadata": "", "PortNumber": 8883, "HostAddress": "::1", "Id": "AUTOIP_::1_2" }, { "Metadata": "", "PortNumber": 8883, "HostAddress": "fe80::1e69:ed93:f5b:f6d", "Id": "AUTOIP_fe80::1e69:ed93:f5b:f6d_3" } ] }

下列程式碼範例會示範如何使用get-connector-definition-version

AWS CLI

檢視有關連接器定義特定版本的資訊

下列get-connector-definition-version範例會擷取有關指定連接器定義之指定版本的資訊。若要擷取連接器定義的所有版本的 ID,請使用list-connector-definition-versions指令。若要擷取新增至連接器定義的最後一個版本的 ID,請使用get-connector-definition指令並檢查內LatestVersion容。

aws greengrass get-connector-definition-version \ --connector-definition-id "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8" \ --connector-definition-version-id "63c57963-c7c2-4a26-a7e2-7bf478ea2623"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8/versions/63c57963-c7c2-4a26-a7e2-7bf478ea2623", "CreationTimestamp": "2019-06-19T19:30:01.300Z", "Definition": { "Connectors": [ { "ConnectorArn": "arn:aws:greengrass:us-west-2::/connectors/SNS/versions/1", "Id": "MySNSConnector", "Parameters": { "DefaultSNSArn": "arn:aws:sns:us-west-2:123456789012:GGConnectorTopic" } } ] }, "Id": "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "Version": "63c57963-c7c2-4a26-a7e2-7bf478ea2623" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用 Greengrass 連接器與服務和通訊協定整合

下列程式碼範例會示範如何使用get-connector-definition

AWS CLI

若要擷取有關連接器定義的資訊

下列get-connector-definition範例會擷取有關指定連接器定義的資訊。若要擷取連接器定義的 ID,請使用list-connector-definitions指令。

aws greengrass get-connector-definition \ --connector-definition-id "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "CreationTimestamp": "2019-06-19T19:30:01.300Z", "Id": "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "LastUpdatedTimestamp": "2019-06-19T19:30:01.300Z", "LatestVersion": "63c57963-c7c2-4a26-a7e2-7bf478ea2623", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8/versions/63c57963-c7c2-4a26-a7e2-7bf478ea2623", "Name": "MySNSConnector", "tags": {} }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用 Greengrass 連接器與服務和通訊協定整合

下列程式碼範例會示範如何使用get-core-definition-version

AWS CLI

若要擷取有關 Greengrass 核心定義特定版本的詳細資訊

下列get-core-definition-version範例會擷取有關指定核心定義之指定版本的資訊。若要擷取核心定義的所有版本的 ID,請使用list-core-definition-versions指令。若要擷取新增至核心定義的最後一個版本的 ID,請使用get-core-definition指令並檢查LatestVersion屬性。

aws greengrass get-core-definition-version \ --core-definition-id "c906ed39-a1e3-4822-a981-7b9bd57b4b46" \ --core-definition-version-id "42aeeac3-fd9d-4312-a8fd-ffa9404a20e0"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/c906ed39-a1e3-4822-a981-7b9bd57b4b46/versions/42aeeac3-fd9d-4312-a8fd-ffa9404a20e0", "CreationTimestamp": "2019-06-18T16:21:21.351Z", "Definition": { "Cores": [ { "CertificateArn": "arn:aws:iot:us-west-2:123456789012:cert/928dea7b82331b47c3ff77b0e763fc5e64e2f7c884e6ef391baed9b6b8e21b45", "Id": "1a39aac7-0885-4417-91f6-23e4cea6c511", "SyncShadow": false, "ThingArn": "arn:aws:iot:us-west-2:123456789012:thing/GGGroup4Pi3_Core" } ] }, "Id": "c906ed39-a1e3-4822-a981-7b9bd57b4b46", "Version": "42aeeac3-fd9d-4312-a8fd-ffa9404a20e0" }

下列程式碼範例會示範如何使用get-core-definition

AWS CLI

若要擷取 Greengrass 核心定義的詳細資訊

下列get-core-definition範例會擷取有關指定核心定義的資訊。若要擷取核心定義的 ID,請使用list-core-definitions指令。

aws greengrass get-core-definition \ --core-definition-id "c906ed39-a1e3-4822-a981-7b9bd57b4b46"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/237d6916-27cf-457f-ba0c-e86cfb5d25cd", "CreationTimestamp": "2018-10-18T04:47:06.721Z", "Id": "237d6916-27cf-457f-ba0c-e86cfb5d25cd", "LastUpdatedTimestamp": "2018-10-18T04:47:06.721Z", "LatestVersion": "bd2cd6d4-2bc5-468a-8962-39e071e34b68", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/237d6916-27cf-457f-ba0c-e86cfb5d25cd/versions/bd2cd6d4-2bc5-468a-8962-39e071e34b68", "tags": {} }

下列程式碼範例會示範如何使用get-deployment-status

AWS CLI

擷取部署狀態的步驟

下列get-deployment-status範例會擷取指定 Greengrass 群組之指定部署的狀態。若要取得部署 ID,請使用指list-deployments令並指定群組 ID。

aws greengrass get-deployment-status \ --group-id "1013db12-8b58-45ff-acc7-704248f66731" \ --deployment-id "1065b8a0-812b-4f21-9d5d-e89b232a530f"

輸出:

{ "DeploymentStatus": "Success", "DeploymentType": "NewDeployment", "UpdatedAt": "2019-06-18T17:04:44.761Z" }

下列程式碼範例會示範如何使用get-device-definition-version

AWS CLI

取得裝置定義版本

下列get-device-definition-version範例會擷取有關指定裝置定義之指定版本的資訊。若要擷取裝置定義的所有版本的 ID,請使用list-device-definition-versions指令。若要擷取新增至裝置定義的最後一個版本的 ID,請使用get-device-definition指令並檢查內LatestVersion容。

aws greengrass get-device-definition-version \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd" \ --device-definition-version-id "83c13984-6fed-447e-84d5-5b8aa45d5f71"

輸出:

{ "Definition": { "Devices": [ { "CertificateArn": "arn:aws:iot:us-west-2:123456789012:cert/6c52ce1b47bde88a637e9ccdd45fe4e4c2c0a75a6866f8f63d980ee22fa51e02", "ThingArn": "arn:aws:iot:us-west-2:123456789012:thing/ExteriorTherm", "SyncShadow": true, "Id": "ExteriorTherm" }, { "CertificateArn": "arn:aws:iot:us-west-2:123456789012:cert/66a415ec415668c2349a76170b64ac0878231c1e21ec83c10e92a18bd568eb92", "ThingArn": "arn:aws:iot:us-west-2:123456789012:thing/InteriorTherm", "SyncShadow": true, "Id": "InteriorTherm" } ] }, "Version": "83c13984-6fed-447e-84d5-5b8aa45d5f71", "CreationTimestamp": "2019-09-11T00:15:09.838Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/83c13984-6fed-447e-84d5-5b8aa45d5f71" }

下列程式碼範例會示範如何使用get-device-definition

AWS CLI

取得裝置定義

下列get-device-definition範例會擷取有關指定裝置定義的資訊。若要擷取裝置定義的 ID,請使用list-device-definitions指令。

aws greengrass get-device-definition \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd"

輸出:

{ "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/83c13984-6fed-447e-84d5-5b8aa45d5f71", "Name": "TemperatureSensors", "tags": {}, "LastUpdatedTimestamp": "2019-09-11T00:19:03.698Z", "LatestVersion": "83c13984-6fed-447e-84d5-5b8aa45d5f71", "CreationTimestamp": "2019-09-11T00:11:06.197Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd" }

下列程式碼範例會示範如何使用get-function-definition-version

AWS CLI

若要擷取有關 Lambda 函數特定版本的詳細資訊

以下內容get-function-definition-version擷取有關指定函數定義之指定版本的資訊。若要擷取函數定義的所有版本的 ID,請使用list-function-definition-versions指令。若要擷取新增至函數定義的最後一個版本的 ID,請使用get-function-definition指令並檢查LatestVersion屬性。

aws greengrass get-function-definition-version \ --function-definition-id "063f5d1a-1dd1-40b4-9b51-56f8993d0f85" \ --function-definition-version-id "9748fda7-1589-4fcc-ac94-f5559e88678b"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9748fda7-1589-4fcc-ac94-f5559e88678b", "CreationTimestamp": "2019-06-18T17:04:30.776Z", "Definition": { "Functions": [ { "FunctionArn": "arn:aws:lambda:::function:GGIPDetector:1", "FunctionConfiguration": { "Environment": {}, "MemorySize": 32768, "Pinned": true, "Timeout": 3 }, "Id": "26b69bdb-e547-46bc-9812-84ec04b6cc8c" }, { "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:Greengrass_HelloWorld:GG_HelloWorld", "FunctionConfiguration": { "EncodingType": "json", "Environment": { "Variables": {} }, "MemorySize": 16384, "Pinned": true, "Timeout": 25 }, "Id": "384465a8-eedf-48c6-b793-4c35f7bfae9b" } ] }, "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "Version": "9748fda7-1589-4fcc-ac94-f5559e88678b" }

下列程式碼範例會示範如何使用get-function-definition

AWS CLI

擷取函數定義

下列get-function-definition範例會顯示指定函數定義的詳細資訊。若要擷取函數定義的 ID,請使用list-function-definitions指令。

aws greengrass get-function-definition \ --function-definition-id "063f5d1a-1dd1-40b4-9b51-56f8993d0f85"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "CreationTimestamp": "2019-06-18T16:21:21.431Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "LastUpdatedTimestamp": "2019-06-18T16:21:21.431Z", "LatestVersion": "9748fda7-1589-4fcc-ac94-f5559e88678b", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9748fda7-1589-4fcc-ac94-f5559e88678b", "tags": {} }

下列程式碼範例會示範如何使用get-group-certificate-authority

AWS CLI

若要擷取與綠色群組相關聯的 CA

下列get-group-certificate-authority範例會擷取與指定之 Greengrass 群組相關聯的憑證授權單位 (CA)。若要取得憑證授權單位 ID,請使用指list-group-certificate-authorities令並指定群組 ID。

aws greengrass get-group-certificate-authority \ --group-id "1013db12-8b58-45ff-acc7-704248f66731" \ --certificate-authority-id "f0430e1736ea8ed30cc5d5de9af67a7e3586bad9ae4d89c2a44163f65fdd8cf6"

輸出:

{ "GroupCertificateAuthorityArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/certificateauthorities/f0430e1736ea8ed30cc5d5de9af67a7e3586bad9ae4d89c2a44163f65fdd8cf6", "GroupCertificateAuthorityId": "f0430e1736ea8ed30cc5d5de9af67a7e3586bad9ae4d89c2a44163f65fdd8cf6", "PemEncodedCertificate": "-----BEGIN CERTIFICATE----- MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBWEXAMPLEGA1UEBhMC VVMxCzAJBgNVBAgTAldBMRAwDEXAMPLEEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6 b24xFDASBgNVBAEXAMPLESBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd BgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jEXAMPLENMTEwNDI1MjA0NTIxWhcN MTIwNDI0MjA0EXAMPLEBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYD VQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWEXAMPLEDASBgNVBAsTC0lBTSBDb25z b2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWEXAMPLEgkqhkiG9w0BCQEWEG5vb25lQGFt YXpvbi5EXAMPLE8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ 21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CEXAMPLE93vUEIO3IyNoH/f0wYK8m9T rDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswYEXAMPLEgpE Ibb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKEXAMPLEAQEFBQADgYEAtCu4 nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0Fkb FFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTb NYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE= -----END CERTIFICATE-----\n" }

下列程式碼範例會示範如何使用get-group-certificate-configuration

AWS CLI

擷取 Greengrass 群組所使用之憑證授權單位的組態

下列get-group-certificate-configuration範例會擷取指定 Greengrass 群組所使用之憑證授權單位 (CA) 的組態。

aws greengrass get-group-certificate-configuration \ --group-id "1013db12-8b58-45ff-acc7-704248f66731"

輸出:

{ "CertificateAuthorityExpiryInMilliseconds": 2524607999000, "CertificateExpiryInMilliseconds": 604800000, "GroupId": "1013db12-8b58-45ff-acc7-704248f66731" }

下列程式碼範例會示範如何使用get-group-version

AWS CLI

若要擷取有關 Greengrass 群組版本的資訊

下列get-group-version範例會擷取指定群組之指定版本的相關資訊。若要擷取群組所有版本的 ID,請使用list-group-versions指令。若要擷取新增至群組的最後一個版本的 ID,請使用get-group指令並檢查LatestVersion屬性。

aws greengrass get-group-version \ --group-id "1013db12-8b58-45ff-acc7-704248f66731" \ --group-version-id "115136b3-cfd7-4462-b77f-8741a4b00e5e"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/115136b3-cfd7-4462-b77f-8741a4b00e5e", "CreationTimestamp": "2019-06-18T17:04:30.915Z", "Definition": { "CoreDefinitionVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/c906ed39-a1e3-4822-a981-7b9bd57b4b46/versions/42aeeac3-fd9d-4312-a8fd-ffa9404a20e0", "FunctionDefinitionVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9748fda7-1589-4fcc-ac94-f5559e88678b", "SubscriptionDefinitionVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/88ae8699-12ac-4663-ba3f-4d7f0519140b" }, "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "115136b3-cfd7-4462-b77f-8741a4b00e5e" }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetGroupVersion中的。

下列程式碼範例會示範如何使用get-group

AWS CLI

若要擷取有關綠色群組的資訊

下列get-group範例會擷取有關指定 Greengrass 群組的資訊。若要擷取群組的 ID,請使用指list-groups令。

aws greengrass get-group \ --group-id "1013db12-8b58-45ff-acc7-704248f66731"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731", "CreationTimestamp": "2019-06-18T16:21:21.457Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "LastUpdatedTimestamp": "2019-06-18T16:21:21.457Z", "LatestVersion": "115136b3-cfd7-4462-b77f-8741a4b00e5e", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/115136b3-cfd7-4462-b77f-8741a4b00e5e", "Name": "GGGroup4Pi3", "tags": {} }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetGroup中的。

下列程式碼範例會示範如何使用get-logger-definition-version

AWS CLI

擷取有關記錄器定義版本的資訊

下列get-logger-definition-version範例會擷取有關指定記錄器定義之指定版本的資訊。若要擷取記錄器定義的所有版本的 ID,請使用list-logger-definition-versions指令。若要擷取新增至記錄器定義的最後一個版本的 ID,請使用get-logger-definition指令並檢查LatestVersion屬性。

aws greengrass get-logger-definition-version \ --logger-definition-id "49eeeb66-f1d3-4e34-86e3-3617262abf23" \ --logger-definition-version-id "5e3f6f64-a565-491e-8de0-3c0d8e0f2073"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23/versions/5e3f6f64-a565-491e-8de0-3c0d8e0f2073", "CreationTimestamp": "2019-05-08T16:10:13.866Z", "Definition": { "Loggers": [] }, "Id": "49eeeb66-f1d3-4e34-86e3-3617262abf23", "Version": "5e3f6f64-a565-491e-8de0-3c0d8e0f2073" }

下列程式碼範例會示範如何使用get-logger-definition

AWS CLI

若要擷取有關記錄器定義的資訊

下列get-logger-definition範例會擷取有關指定記錄器定義的資訊。若要擷取記錄器定義的 ID,請使用list-logger-definitions指令。

aws greengrass get-logger-definition \ --logger-definition-id "49eeeb66-f1d3-4e34-86e3-3617262abf23"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23", "CreationTimestamp": "2019-05-08T16:10:13.809Z", "Id": "49eeeb66-f1d3-4e34-86e3-3617262abf23", "LastUpdatedTimestamp": "2019-05-08T16:10:13.809Z", "LatestVersion": "5e3f6f64-a565-491e-8de0-3c0d8e0f2073", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23/versions/5e3f6f64-a565-491e-8de0-3c0d8e0f2073", "tags": {} }

下列程式碼範例會示範如何使用get-resource-definition-version

AWS CLI

若要擷取有關特定資源定義版本的資訊

下列get-resource-definition-version範例會擷取有關指定資源定義之指定版本的資訊。若要擷取資源定義的所有版本的 ID,請使用list-resource-definition-versions指令。若要擷取新增至資源定義的最後一個版本的 ID,請使用get-resource-definition指令並檢查LatestVersion屬性。

aws greengrass get-resource-definition-version \ --resource-definition-id "ad8c101d-8109-4b0e-b97d-9cc5802ab658" \ --resource-definition-version-id "26e8829a-491a-464d-9c87-664bf6f6f2be"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658/versions/26e8829a-491a-464d-9c87-664bf6f6f2be", "CreationTimestamp": "2019-06-19T16:40:59.392Z", "Definition": { "Resources": [ { "Id": "26ff3f7b-839a-4217-9fdc-a218308b3963", "Name": "usb-port", "ResourceDataContainer": { "LocalDeviceResourceData": { "GroupOwnerSetting": { "AutoAddGroupOwner": false }, "SourcePath": "/dev/bus/usb" } } } ] }, "Id": "ad8c101d-8109-4b0e-b97d-9cc5802ab658", "Version": "26e8829a-491a-464d-9c87-664bf6f6f2be" }

下列程式碼範例會示範如何使用get-resource-definition

AWS CLI

若要擷取有關資源定義的資訊

下列get-resource-definition範例會擷取有關指定資源定義的資訊。若要擷取資源定義的 ID,請使用list-resource-definitions指令。

aws greengrass get-resource-definition \ --resource-definition-id "ad8c101d-8109-4b0e-b97d-9cc5802ab658"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658", "CreationTimestamp": "2019-06-19T16:40:59.261Z", "Id": "ad8c101d-8109-4b0e-b97d-9cc5802ab658", "LastUpdatedTimestamp": "2019-06-19T16:40:59.261Z", "LatestVersion": "26e8829a-491a-464d-9c87-664bf6f6f2be", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658/versions/26e8829a-491a-464d-9c87-664bf6f6f2be", "tags": {} }

下列程式碼範例會示範如何使用get-service-role-for-account

AWS CLI

擷取附加至您帳戶之服務角色的詳細資料

下列get-service-role-for-account範例會擷取附加至您 AWS 帳戶之服務角色的相關資訊。

aws greengrass get-service-role-for-account

輸出:

{ "AssociatedAt": "2018-10-18T15:59:20Z", "RoleArn": "arn:aws:iam::123456789012:role/service-role/Greengrass_ServiceRole" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的《Gre engrass 服務角色》。

下列程式碼範例會示範如何使用get-subscription-definition-version

AWS CLI

若要擷取訂閱定義之特定版本的相關資訊

下列get-subscription-definition-version範例會擷取有關指定訂閱定義之指定版本的資訊。若要擷取訂閱定義的所有版本的 ID,請使用list-subscription-definition-versions指令。若要擷取新增至訂閱定義的最後一個版本的 ID,請使用get-subscription-definition命令並檢查內LatestVersion容。

aws greengrass get-subscription-definition-version \ --subscription-definition-id "70e49321-83d5-45d2-bc09-81f4917ae152" \ --subscription-definition-version-id "88ae8699-12ac-4663-ba3f-4d7f0519140b"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/88ae8699-12ac-4663-ba3f-4d7f0519140b", "CreationTimestamp": "2019-06-18T17:03:52.499Z", "Definition": { "Subscriptions": [ { "Id": "692c4484-d89f-4f64-8edd-1a041a65e5b6", "Source": "arn:aws:lambda:us-west-2:123456789012:function:Greengrass_HelloWorld:GG_HelloWorld", "Subject": "hello/world", "Target": "cloud" } ] }, "Id": "70e49321-83d5-45d2-bc09-81f4917ae152", "Version": "88ae8699-12ac-4663-ba3f-4d7f0519140b" }

下列程式碼範例會示範如何使用get-subscription-definition

AWS CLI

若要擷取訂閱定義的相關資訊

下列get-subscription-definition範例會擷取有關指定訂閱定義的資訊。若要擷取訂閱定義的 ID,請使用list-subscription-definitions指令。

aws greengrass get-subscription-definition \ --subscription-definition-id "70e49321-83d5-45d2-bc09-81f4917ae152"

輸出:

{ "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152", "CreationTimestamp": "2019-06-18T17:03:52.392Z", "Id": "70e49321-83d5-45d2-bc09-81f4917ae152", "LastUpdatedTimestamp": "2019-06-18T17:03:52.392Z", "LatestVersion": "88ae8699-12ac-4663-ba3f-4d7f0519140b", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/88ae8699-12ac-4663-ba3f-4d7f0519140b", "tags": {} }

下列程式碼範例會示範如何使用get-thing-runtime-configuration

AWS CLI

若要擷取 Greengrass 核心的執行階段組態

下列get-thing-runtime-configuration範例會擷取 Greengrass 核心的執行階段組態。擷取執行階段組態之前,您必須先使用update-thing-runtime-configuration指令來建立核心的執行階段組態。

aws greengrass get-thing-runtime-configuration \ --thing-name SampleGreengrassCore

輸出:

{ "RuntimeConfiguration": { "TelemetryConfiguration": { "ConfigurationSyncStatus": "OutOfSync", "Telemetry": "On" } } }

如需詳細資訊,請參AWS IoT Greengrass 開發人員指南中的設定遙測設定。

下列程式碼範例會示範如何使用list-bulk-deployment-detailed-reports

AWS CLI

列出大量部署中個別部署的相關資訊

下列list-bulk-deployment-detailed-reports範例顯示大量部署作業中個別部署的相關資訊,包括狀態。

aws greengrass list-bulk-deployment-detailed-reports \ --bulk-deployment-id 42ce9c42-489b-4ed4-b905-8996aa50ef9d

輸出:

{ "Deployments": [ { "DeploymentType": "NewDeployment", "DeploymentStatus": "Success", "DeploymentId": "123456789012:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "DeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333/deployments/123456789012:123456789012:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "GroupArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333/versions/123456789012:a1b2c3d4-5678-90ab-cdef-EXAMPLE44444", "CreatedAt": "2020-01-21T21:34:16.501Z" }, { "DeploymentType": "NewDeployment", "DeploymentStatus": "InProgress", "DeploymentId": "123456789012:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "DeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/a1b2c3d4-5678-90ab-cdef-EXAMPLE55555/deployments/123456789012:123456789012:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "GroupArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/a1b2c3d4-5678-90ab-cdef-EXAMPLE55555/versions/a1b2c3d4-5678-90ab-cdef-EXAMPLE66666", "CreatedAt": "2020-01-21T21:34:16.486Z" }, ... ] }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的為群組建立大量部署

下列程式碼範例會示範如何使用list-bulk-deployments

AWS CLI

列出大量部署

下列list-bulk-deployments範例會列出所有大量部署。

aws greengrass list-bulk-deployments

輸出:

{ "BulkDeployments": [ { "BulkDeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/bulk/deployments/870fb41b-6288-4e0c-bc76-a7ba4b4d3267", "BulkDeploymentId": "870fb41b-6288-4e0c-bc76-a7ba4b4d3267", "CreatedAt": "2019-06-25T16:11:33.265Z" } ] }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的為群組建立大量部署

下列程式碼範例會示範如何使用list-connector-definition-versions

AWS CLI

列出可用於連接器定義的版本的步驟

下列list-connector-definition-versions範例列出可用於指定連接器定義的版本。使用指list-connector-definitions令取得連接器定義 ID。

aws greengrass list-connector-definition-versions \ --connector-definition-id "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8/versions/63c57963-c7c2-4a26-a7e2-7bf478ea2623", "CreationTimestamp": "2019-06-19T19:30:01.300Z", "Id": "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "Version": "63c57963-c7c2-4a26-a7e2-7bf478ea2623" } ] }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用 Greengrass 連接器與服務和通訊協定整合

下列程式碼範例會示範如何使用list-connector-definitions

AWS CLI

若要列出已定義的 Greengrass 連接器

下列list-connector-definitions範例會列出為您的帳戶定義的所有 Greengrass 連接器。 AWS

aws greengrass list-connector-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "CreationTimestamp": "2019-06-19T19:30:01.300Z", "Id": "b5c4ebfd-f672-49a3-83cd-31c7216a7bb8", "LastUpdatedTimestamp": "2019-06-19T19:30:01.300Z", "LatestVersion": "63c57963-c7c2-4a26-a7e2-7bf478ea2623", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/connectors/b5c4ebfd-f672-49a3-83cd-31c7216a7bb8/versions/63c57963-c7c2-4a26-a7e2-7bf478ea2623", "Name": "MySNSConnector" } ] }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用 Greengrass 連接器與服務和通訊協定整合

下列程式碼範例會示範如何使用list-core-definition-versions

AWS CLI

若要列出 Greengrass 核心定義的版本

下列list-core-definitions範例會列出特定 Greengrass 核心定義的所有版本。您可以使用list-core-definitions指令取得版本 ID。

aws greengrass list-core-definition-versions \ --core-definition-id "eaf280cb-138c-4d15-af36-6f681a1348f7"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/eaf280cb-138c-4d15-af36-6f681a1348f7/versions/467c36e4-c5da-440c-a97b-084e62593b4c", "CreationTimestamp": "2019-06-18T16:14:17.709Z", "Id": "eaf280cb-138c-4d15-af36-6f681a1348f7", "Version": "467c36e4-c5da-440c-a97b-084e62593b4c" } ] }

下列程式碼範例會示範如何使用list-core-definitions

AWS CLI

若要列出 Greengrass 核心定義

下列list-core-definitions範例會列出您帳戶的所有 Greengrass 核心定義。 AWS

aws greengrass list-core-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/0507843c-c1ef-4f06-b051-817030df7e7d", "CreationTimestamp": "2018-10-17T04:30:32.786Z", "Id": "0507843c-c1ef-4f06-b051-817030df7e7d", "LastUpdatedTimestamp": "2018-10-17T04:30:32.786Z", "LatestVersion": "bcdf9e86-3793-491e-93af-3cdfbf4e22b7", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/0507843c-c1ef-4f06-b051-817030df7e7d/versions/bcdf9e86-3793-491e-93af-3cdfbf4e22b7" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/31c22500-3509-4271-bafd-cf0655cda438", "CreationTimestamp": "2019-06-18T16:24:16.064Z", "Id": "31c22500-3509-4271-bafd-cf0655cda438", "LastUpdatedTimestamp": "2019-06-18T16:24:16.064Z", "LatestVersion": "2f350395-6d09-4c8a-8336-9ae5b57ace84", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/31c22500-3509-4271-bafd-cf0655cda438/versions/2f350395-6d09-4c8a-8336-9ae5b57ace84" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/c906ed39-a1e3-4822-a981-7b9bd57b4b46", "CreationTimestamp": "2019-06-18T16:21:21.351Z", "Id": "c906ed39-a1e3-4822-a981-7b9bd57b4b46", "LastUpdatedTimestamp": "2019-06-18T16:21:21.351Z", "LatestVersion": "42aeeac3-fd9d-4312-a8fd-ffa9404a20e0", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/c906ed39-a1e3-4822-a981-7b9bd57b4b46/versions/42aeeac3-fd9d-4312-a8fd-ffa9404a20e0" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/eaf280cb-138c-4d15-af36-6f681a1348f7", "CreationTimestamp": "2019-06-18T16:14:17.709Z", "Id": "eaf280cb-138c-4d15-af36-6f681a1348f7", "LastUpdatedTimestamp": "2019-06-18T16:14:17.709Z", "LatestVersion": "467c36e4-c5da-440c-a97b-084e62593b4c", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/cores/eaf280cb-138c-4d15-af36-6f681a1348f7/versions/467c36e4-c5da-440c-a97b-084e62593b4c" } ] }

下列程式碼範例會示範如何使用list-deployments

AWS CLI

若要列出 Greengrass 群組的部署

下列list-deployments範例會列出指定 Greengrass 群組的部署。您可以使用list-groups指令來查詢您的群組 ID。

aws greengrass list-deployments \ --group-id "1013db12-8b58-45ff-acc7-704248f66731"

輸出:

{ "Deployments": [ { "CreatedAt": "2019-06-18T17:04:32.702Z", "DeploymentId": "1065b8a0-812b-4f21-9d5d-e89b232a530f", "DeploymentType": "NewDeployment", "GroupArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/115136b3-cfd7-4462-b77f-8741a4b00e5e" } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListDeployments中的。

下列程式碼範例會示範如何使用list-device-definition-versions

AWS CLI

列出裝置定義的版本

下列list-device-definition-versions範例顯示與指定裝置定義相關聯的裝置定義版本。

aws greengrass list-device-definition-versions \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd"

輸出:

{ "Versions": [ { "Version": "83c13984-6fed-447e-84d5-5b8aa45d5f71", "CreationTimestamp": "2019-09-11T00:15:09.838Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/83c13984-6fed-447e-84d5-5b8aa45d5f71" }, { "Version": "3b5cc510-58c1-44b5-9d98-4ad858ffa795", "CreationTimestamp": "2019-09-11T00:11:06.197Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/3b5cc510-58c1-44b5-9d98-4ad858ffa795" } ] }

下列程式碼範例會示範如何使用list-device-definitions

AWS CLI

列出您的裝置定義

下列list-device-definitions範例會顯示指定 AWS 區域中您 AWS 帳戶中裝置定義的詳細資料。

aws greengrass list-device-definitions \ --region us-west-2

輸出:

{ "Definitions": [ { "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/50f3274c-3f0a-4f57-b114-6f46085281ab/versions/c777b0f5-1059-449b-beaa-f003ebc56c34", "LastUpdatedTimestamp": "2019-06-14T15:42:09.059Z", "LatestVersion": "c777b0f5-1059-449b-beaa-f003ebc56c34", "CreationTimestamp": "2019-06-14T15:42:09.059Z", "Id": "50f3274c-3f0a-4f57-b114-6f46085281ab", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/50f3274c-3f0a-4f57-b114-6f46085281ab" }, { "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/e01951c9-6134-479a-969a-1a15cac11c40/versions/514d57aa-4ee6-401c-9fac-938a9f7a51e5", "Name": "TestDeviceDefinition", "LastUpdatedTimestamp": "2019-04-16T23:17:43.245Z", "LatestVersion": "514d57aa-4ee6-401c-9fac-938a9f7a51e5", "CreationTimestamp": "2019-04-16T23:17:43.245Z", "Id": "e01951c9-6134-479a-969a-1a15cac11c40", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/e01951c9-6134-479a-969a-1a15cac11c40" }, { "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd/versions/83c13984-6fed-447e-84d5-5b8aa45d5f71", "Name": "TemperatureSensors", "LastUpdatedTimestamp": "2019-09-10T00:19:03.698Z", "LatestVersion": "83c13984-6fed-447e-84d5-5b8aa45d5f71", "CreationTimestamp": "2019-09-11T00:11:06.197Z", "Id": "f9ba083d-5ad4-4534-9f86-026a45df1ccd", "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/devices/f9ba083d-5ad4-4534-9f86-026a45df1ccd" } ] }

下列程式碼範例會示範如何使用list-function-definition-versions

AWS CLI

若要列出 Lambda 函數的版本

下列list-function-definition-versions範例會列出指定 Lambda 函數的所有版本。您可以使用list-function-definitions命令來獲取 ID。

aws greengrass list-function-definition-versions \ --function-definition-id "063f5d1a-1dd1-40b4-9b51-56f8993d0f85"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9748fda7-1589-4fcc-ac94-f5559e88678b", "CreationTimestamp": "2019-06-18T17:04:30.776Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "Version": "9748fda7-1589-4fcc-ac94-f5559e88678b" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9b08df77-26f2-4c29-93d2-769715edcfec", "CreationTimestamp": "2019-06-18T17:02:44.087Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "Version": "9b08df77-26f2-4c29-93d2-769715edcfec" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/4236239f-94f7-4b90-a2f8-2a24c829d21e", "CreationTimestamp": "2019-06-18T17:01:42.284Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "Version": "4236239f-94f7-4b90-a2f8-2a24c829d21e" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/343408bb-549a-4fbe-b043-853643179a39", "CreationTimestamp": "2019-06-18T16:21:21.431Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "Version": "343408bb-549a-4fbe-b043-853643179a39" } ] }

下列程式碼範例會示範如何使用list-function-definitions

AWS CLI

若要列出 Lambda 函數

下列list-function-definitions範例會列出為您的 AWS 帳戶定義的所有 Lambda 函數。

aws greengrass list-function-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/017970a5-8952-46dd-b1c1-020b3ae8e960", "CreationTimestamp": "2018-10-17T04:30:32.884Z", "Id": "017970a5-8952-46dd-b1c1-020b3ae8e960", "LastUpdatedTimestamp": "2018-10-17T04:30:32.884Z", "LatestVersion": "4380b302-790d-4ed8-92bf-02e88afecb15", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/017970a5-8952-46dd-b1c1-020b3ae8e960/versions/4380b302-790d-4ed8-92bf-02e88afecb15" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "CreationTimestamp": "2019-06-18T16:21:21.431Z", "Id": "063f5d1a-1dd1-40b4-9b51-56f8993d0f85", "LastUpdatedTimestamp": "2019-06-18T16:21:21.431Z", "LatestVersion": "9748fda7-1589-4fcc-ac94-f5559e88678b", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/063f5d1a-1dd1-40b4-9b51-56f8993d0f85/versions/9748fda7-1589-4fcc-ac94-f5559e88678b" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/6598e653-a262-440c-9967-e2697f64da7b", "CreationTimestamp": "2019-06-18T16:24:16.123Z", "Id": "6598e653-a262-440c-9967-e2697f64da7b", "LastUpdatedTimestamp": "2019-06-18T16:24:16.123Z", "LatestVersion": "38bc6ccd-98a2-4ce7-997e-16c84748fae4", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/6598e653-a262-440c-9967-e2697f64da7b/versions/38bc6ccd-98a2-4ce7-997e-16c84748fae4" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/c668df84-fad2-491b-95f4-655d2cad7885", "CreationTimestamp": "2019-06-18T16:14:17.784Z", "Id": "c668df84-fad2-491b-95f4-655d2cad7885", "LastUpdatedTimestamp": "2019-06-18T16:14:17.784Z", "LatestVersion": "37dd68c4-a64f-40ba-aa13-71fecc3ebded", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/functions/c668df84-fad2-491b-95f4-655d2cad7885/versions/37dd68c4-a64f-40ba-aa13-71fecc3ebded" } ] }

下列程式碼範例會示範如何使用list-group-certificate-authorities

AWS CLI

若要列出群組的目前 CA

下列list-group-certificate-authorities範例會列出指定 Greengrass 群組的目前憑證授權單位 (CA)。

aws greengrass list-group-certificate-authorities \ --group-id "1013db12-8b58-45ff-acc7-704248f66731"

輸出:

{ "GroupCertificateAuthorities": [ { "GroupCertificateAuthorityArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/certificateauthorities/f0430e1736ea8ed30cc5d5de9af67a7e3586bad9ae4d89c2a44163f65fdd8cf6", "GroupCertificateAuthorityId": "f0430e1736ea8ed30cc5d5de9af67a7e3586bad9ae4d89c2a44163f65fdd8cf6" } ] }

下列程式碼範例會示範如何使用list-group-versions

AWS CLI

若要列出 Greengrass 群組的版本

下列list-group-versions範例會列出指定的 Greengrass 群組的版本。

aws greengrass list-group-versions \ --group-id "1013db12-8b58-45ff-acc7-704248f66731"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/115136b3-cfd7-4462-b77f-8741a4b00e5e", "CreationTimestamp": "2019-06-18T17:04:30.915Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "115136b3-cfd7-4462-b77f-8741a4b00e5e" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/4340669d-d14d-44e3-920c-46c928750750", "CreationTimestamp": "2019-06-18T17:03:52.663Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "4340669d-d14d-44e3-920c-46c928750750" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/1b06e099-2d5b-4f10-91b9-78c4e060f5da", "CreationTimestamp": "2019-06-18T17:02:44.189Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "1b06e099-2d5b-4f10-91b9-78c4e060f5da" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/2d3f27f1-3b43-4554-ab7a-73ec30477efe", "CreationTimestamp": "2019-06-18T17:01:42.401Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "2d3f27f1-3b43-4554-ab7a-73ec30477efe" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/d20f7ae9-3444-4c1c-b025-e2ede23cdd31", "CreationTimestamp": "2019-06-18T16:21:21.457Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "Version": "d20f7ae9-3444-4c1c-b025-e2ede23cdd31" } ] }

下列程式碼範例會示範如何使用list-groups

AWS CLI

若要列出 Greengrass 群組

下列list-groups範例會列出您帳戶中定義的所有 Greengrass 群組。 AWS

aws greengrass list-groups

輸出:

{ "Groups": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731", "CreationTimestamp": "2019-06-18T16:21:21.457Z", "Id": "1013db12-8b58-45ff-acc7-704248f66731", "LastUpdatedTimestamp": "2019-06-18T16:21:21.457Z", "LatestVersion": "115136b3-cfd7-4462-b77f-8741a4b00e5e", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731/versions/115136b3-cfd7-4462-b77f-8741a4b00e5e", "Name": "GGGroup4Pi3" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1402daf9-71cf-4cfe-8be0-d5e80526d0d8", "CreationTimestamp": "2018-10-31T21:52:46.603Z", "Id": "1402daf9-71cf-4cfe-8be0-d5e80526d0d8", "LastUpdatedTimestamp": "2018-10-31T21:52:46.603Z", "LatestVersion": "749af901-60ab-456f-a096-91b12d983c29", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1402daf9-71cf-4cfe-8be0-d5e80526d0d8/versions/749af901-60ab-456f-a096-91b12d983c29", "Name": "MyTestGroup" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/504b5c8d-bbed-4635-aff1-48ec5b586db5", "CreationTimestamp": "2018-12-31T21:39:36.771Z", "Id": "504b5c8d-bbed-4635-aff1-48ec5b586db5", "LastUpdatedTimestamp": "2018-12-31T21:39:36.771Z", "LatestVersion": "46911e8e-f9bc-4898-8b63-59c7653636ec", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/504b5c8d-bbed-4635-aff1-48ec5b586db5/versions/46911e8e-f9bc-4898-8b63-59c7653636ec", "Name": "smp-ggrass-group" } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListGroups中的。

下列程式碼範例會示範如何使用list-logger-definition-versions

AWS CLI

若要取得記錄器定義的版本清單

下列list-logger-definition-versions範例會取得指定記錄器定義之所有版本的清單。

aws greengrass list-logger-definition-versions \ --logger-definition-id "49eeeb66-f1d3-4e34-86e3-3617262abf23"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23/versions/5e3f6f64-a565-491e-8de0-3c0d8e0f2073", "CreationTimestamp": "2019-05-08T16:10:13.866Z", "Id": "49eeeb66-f1d3-4e34-86e3-3617262abf23", "Version": "5e3f6f64-a565-491e-8de0-3c0d8e0f2073" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23/versions/3ec6d3af-eb85-48f9-a16d-1c795fe696d7", "CreationTimestamp": "2019-05-08T16:10:13.809Z", "Id": "49eeeb66-f1d3-4e34-86e3-3617262abf23", "Version": "3ec6d3af-eb85-48f9-a16d-1c795fe696d7" } ] }

下列程式碼範例會示範如何使用list-logger-definitions

AWS CLI

若要取得記錄器定義清單

下列list-logger-definitions範例會列出您 AWS 帳戶的所有記錄器定義。

aws greengrass list-logger-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23", "CreationTimestamp": "2019-05-08T16:10:13.809Z", "Id": "49eeeb66-f1d3-4e34-86e3-3617262abf23", "LastUpdatedTimestamp": "2019-05-08T16:10:13.809Z", "LatestVersion": "5e3f6f64-a565-491e-8de0-3c0d8e0f2073", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/loggers/49eeeb66-f1d3-4e34-86e3-3617262abf23/versions/5e3f6f64-a565-491e-8de0-3c0d8e0f2073" } ] }

下列程式碼範例會示範如何使用list-resource-definition-versions

AWS CLI

若要列出資源定義的版本

下列list-resource-definition-versions範例會列出指定 Greengrass 資源的版本。

aws greengrass list-resource-definition-versions \ --resource-definition-id "ad8c101d-8109-4b0e-b97d-9cc5802ab658"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658/versions/26e8829a-491a-464d-9c87-664bf6f6f2be", "CreationTimestamp": "2019-06-19T16:40:59.392Z", "Id": "ad8c101d-8109-4b0e-b97d-9cc5802ab658", "Version": "26e8829a-491a-464d-9c87-664bf6f6f2be" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658/versions/432d92f6-12de-4ec9-a704-619a942a62aa", "CreationTimestamp": "2019-06-19T16:40:59.261Z", "Id": "ad8c101d-8109-4b0e-b97d-9cc5802ab658", "Version": "432d92f6-12de-4ec9-a704-619a942a62aa" } ] }

下列程式碼範例會示範如何使用list-resource-definitions

AWS CLI

若要列出已定義的資源

下列list-resource-definitions範例會列出為 AWS IoT Greengrass 定義要使用的資源。

aws greengrass list-resource-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658", "CreationTimestamp": "2019-06-19T16:40:59.261Z", "Id": "ad8c101d-8109-4b0e-b97d-9cc5802ab658", "LastUpdatedTimestamp": "2019-06-19T16:40:59.261Z", "LatestVersion": "26e8829a-491a-464d-9c87-664bf6f6f2be", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658/versions/26e8829a-491a-464d-9c87-664bf6f6f2be" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38", "CreationTimestamp": "2019-06-19T21:51:28.212Z", "Id": "c8bb9ebc-c3fd-40a4-9c6a-568d75569d38", "LastUpdatedTimestamp": "2019-06-19T21:51:28.212Z", "LatestVersion": "a5f94d0b-f6bc-40f4-bb78-7a1c5fe13ba1", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/c8bb9ebc-c3fd-40a4-9c6a-568d75569d38/versions/a5f94d0b-f6bc-40f4-bb78-7a1c5fe13ba1", "Name": "MyGreengrassResources" } ] }

下列程式碼範例會示範如何使用list-subscription-definition-versions

AWS CLI

若要列出訂閱定義的版本

下列list-subscription-definition-versions範例會列出指定訂閱的所有版本。您可以使用list-subscription-definitions命令來查詢訂閱識別碼。

aws greengrass list-subscription-definition-versions \ --subscription-definition-id "70e49321-83d5-45d2-bc09-81f4917ae152"

輸出:

{ "Versions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/88ae8699-12ac-4663-ba3f-4d7f0519140b", "CreationTimestamp": "2019-06-18T17:03:52.499Z", "Id": "70e49321-83d5-45d2-bc09-81f4917ae152", "Version": "88ae8699-12ac-4663-ba3f-4d7f0519140b" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/7e320ba3-c369-4069-a2f0-90acb7f219d6", "CreationTimestamp": "2019-06-18T17:03:52.392Z", "Id": "70e49321-83d5-45d2-bc09-81f4917ae152", "Version": "7e320ba3-c369-4069-a2f0-90acb7f219d6" } ] }

下列程式碼範例會示範如何使用list-subscription-definitions

AWS CLI

若要取得訂閱定義清單

下列list-subscription-definitions範例會列出您帳戶中定義的所有 AWS IoT Greengrass 訂閱。 AWS

aws greengrass list-subscription-definitions

輸出:

{ "Definitions": [ { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152", "CreationTimestamp": "2019-06-18T17:03:52.392Z", "Id": "70e49321-83d5-45d2-bc09-81f4917ae152", "LastUpdatedTimestamp": "2019-06-18T17:03:52.392Z", "LatestVersion": "88ae8699-12ac-4663-ba3f-4d7f0519140b", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/70e49321-83d5-45d2-bc09-81f4917ae152/versions/88ae8699-12ac-4663-ba3f-4d7f0519140b" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/cd6f1c37-d9a4-4e90-be94-01a7404f5967", "CreationTimestamp": "2018-10-18T15:45:34.024Z", "Id": "cd6f1c37-d9a4-4e90-be94-01a7404f5967", "LastUpdatedTimestamp": "2018-10-18T15:45:34.024Z", "LatestVersion": "d1cf8fac-284f-4f6a-98fe-a2d36d089373", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/cd6f1c37-d9a4-4e90-be94-01a7404f5967/versions/d1cf8fac-284f-4f6a-98fe-a2d36d089373" }, { "Arn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/fa81bc84-3f59-4377-a84b-5d0134da359b", "CreationTimestamp": "2018-10-22T17:09:31.429Z", "Id": "fa81bc84-3f59-4377-a84b-5d0134da359b", "LastUpdatedTimestamp": "2018-10-22T17:09:31.429Z", "LatestVersion": "086d1b08-b25a-477c-a16f-6f9b3a9c295a", "LatestVersionArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/subscriptions/fa81bc84-3f59-4377-a84b-5d0134da359b/versions/086d1b08-b25a-477c-a16f-6f9b3a9c295a" } ] }

下列程式碼範例會示範如何使用list-tags-for-resource

AWS CLI

若要列出附加至資源的標籤

下列list-tags-for-resource範例會列出附加至指定資源的標籤及其值。

aws greengrass list-tags-for-resource \ --resource-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658"

輸出:

{ "tags": { "ResourceSubType": "USB", "ResourceType": "Device" } }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的標記您的 Gre engrass 資源

下列程式碼範例會示範如何使用reset-deployments

AWS CLI

若要清理 Greengrass 群組的部署資訊

下列reset-deployments範例會清除指定 Greengrass 群組的部署資訊。當您新增時--force option,會重設部署資訊,而不需等待核心裝置回應。

aws greengrass reset-deployments \ --group-id "1402daf9-71cf-4cfe-8be0-d5e80526d0d8" \ --force

輸出:

{ "DeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1402daf9-71cf-4cfe-8be0-d5e80526d0d8/deployments/7dd4e356-9882-46a3-9e28-6d21900c011a", "DeploymentId": "7dd4e356-9882-46a3-9e28-6d21900c011a" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的重設部署

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

下列程式碼範例會示範如何使用start-bulk-deployment

AWS CLI

啟動大量部署作業

下列start-bulk-deployment範例會啟動大量部署作業,使用儲存在 S3 儲存貯體中的檔案來指定要部署的群組。

aws greengrass start-bulk-deployment \ --cli-input-json "{\"InputFileUri\":\"https://gg-group-deployment1.s3-us-west-2.amazonaws.com/MyBulkDeploymentInputFile.txt\", \"ExecutionRoleArn\":\"arn:aws:iam::123456789012:role/ggCreateDeploymentRole\",\"AmznClientToken\":\"yourAmazonClientToken\"}"

輸出:

{ "BulkDeploymentArn": "arn:aws:greengrass:us-west-2:123456789012:/greengrass/bulk/deployments/870fb41b-6288-4e0c-bc76-a7ba4b4d3267", "BulkDeploymentId": "870fb41b-6288-4e0c-bc76-a7ba4b4d3267" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的為群組建立大量部署

下列程式碼範例會示範如何使用stop-bulk-deployment

AWS CLI

停止大量部署

下列stop-bulk-deployment範例會停止指定的大量部署。如果您嘗試停止已完成的大量部署,您會收到錯誤訊息:InvalidInputException: Cannot change state of finished execution.

aws greengrass stop-bulk-deployment \ --bulk-deployment-id "870fb41b-6288-4e0c-bc76-a7ba4b4d3267"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的為群組建立大量部署

下列程式碼範例會示範如何使用tag-resource

AWS CLI

若要將標籤套用至資源

下列tag-resource範例會將兩個標籤ResourceTypeResourceSubType套用至指定的 Greengrass 資源。此操作既可以添加新標籤和值,也可以更新現有標籤的值。使用untag-resource指令移除標籤。

aws greengrass tag-resource \ --resource-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/definition/resources/ad8c101d-8109-4b0e-b97d-9cc5802ab658" \ --tags "ResourceType=Device,ResourceSubType=USB"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的標記您的 Gre engrass 資源

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

下列程式碼範例會示範如何使用untag-resource

AWS CLI

若要從資源中移除標籤及其值

下列untag-resource範例會從指定的 Greengrass 群組移Category除其索引鍵所在的標籤。如果指定資源的索引鍵Category不存在,則不會傳回錯誤。

aws greengrass untag-resource \ --resource-arn "arn:aws:greengrass:us-west-2:123456789012:/greengrass/groups/1013db12-8b58-45ff-acc7-704248f66731" \ --tag-keys "Category"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的標記您的 Gre engrass 資源

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

下列程式碼範例會示範如何使用update-connectivity-info

AWS CLI

若要更新 Greengrass 核心的連線資訊

下列update-connectivity-info範例會變更裝置可用來連線至指定 Greengrass 核心的端點。連線資訊是 IP 位址或網域名稱的清單,以及對應的連接埠號碼和選用的客戶定義的中繼資料。當區域網路變更時,您可能需要更新連線資訊。

aws greengrass update-connectivity-info \ --thing-name "MyGroup_Core" \ --connectivity-info "[{\"Metadata\":\"\",\"PortNumber\":8883,\"HostAddress\":\"127.0.0.1\",\"Id\":\"localhost_127.0.0.1_0\"},{\"Metadata\":\"\",\"PortNumber\":8883,\"HostAddress\":\"192.168.1.3\",\"Id\":\"localIP_192.168.1.3\"}]"

輸出:

{ "Version": "312de337-59af-4cf9-a278-2a23bd39c300" }

下列程式碼範例會示範如何使用update-connector-definition

AWS CLI

更新連接器定義名稱的步驟

下列update-connector-definition範例會更新指定連接器定義的名稱。如果您要更新連接器的詳細資料,請使用create-connector-definition-version指令建立新版本。

aws greengrass update-connector-definition \ --connector-definition-id "55d0052b-0d7d-44d6-b56f-21867215e118" \ --name "GreengrassConnectors2019"

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用連接器與服務和通訊協定整合

下列程式碼範例會示範如何使用update-core-definition

AWS CLI

若要更新核心定義

下列update-core-definition範例會變更指定核心定義的名稱。您只能更新核心定義的name屬性。

aws greengrass update-core-definition \ --core-definition-id "582efe12-b05a-409e-9a24-a2ba1bcc4a12" \ --name "MyCoreDevices"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的設定 AWS IoT Gre engrass 核心

下列程式碼範例會示範如何使用update-device-definition

AWS CLI

更新裝置定義

下列update-device-definition範例會變更指定裝置定義的名稱。您只能更新裝name置定義的內容。

aws greengrass update-device-definition \ --device-definition-id "f9ba083d-5ad4-4534-9f86-026a45df1ccd" \ --name "TemperatureSensors"

此命令不會產生輸出。

下列程式碼範例會示範如何使用update-function-definition

AWS CLI

更新函數定義名稱的步驟

下列update-function-definition範例會更新指定函數定義的名稱。如果要更新函數的詳細資料,請使用create-function-definition-version指令建立新版本。

aws greengrass update-function-definition \ --function-definition-id "e47952bd-dea9-4e2c-a7e1-37bbe8807f46" \ --name ObsoleteFunction

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的執行本機 Lambda 函數

下列程式碼範例會示範如何使用update-group-certificate-configuration

AWS CLI

若要更新群組憑證的到期

下列update-group-certificate-configuration範例會為指定群組產生的憑證設定 10 天的到期日。

aws greengrass update-group-certificate-configuration \ --group-id "8eaadd72-ce4b-4f15-892a-0cc4f3a343f1" \ --certificate-expiry-in-milliseconds 864000000

輸出:

{ "CertificateExpiryInMilliseconds": 864000000, "CertificateAuthorityExpiryInMilliseconds": 2524607999000, "GroupId": "8eaadd72-ce4b-4f15-892a-0cc4f3a343f1" }

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的 AWS IoT 網路安全性

下列程式碼範例會示範如何使用update-group

AWS CLI

更新群組名稱

下列update-group範例會更新指定 Greengrass 群組的名稱。如果您要更新群組的詳細資料,請使用create-group-version指令建立新版本。

aws greengrass update-group \ --group-id "1402daf9-71cf-4cfe-8be0-d5e80526d0d8" \ --name TestGroup4of6

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的在 AWS IoT 上設定 IoT AWS 網路環境。

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

下列程式碼範例會示範如何使用update-logger-definition

AWS CLI

更新記錄器定義

下列update-logger-definition範例會變更指定記錄器定義的名稱。您只能更新記錄器定義的name屬性。

aws greengrass update-logger-definition \ --logger-definition-id "a454b62a-5d56-4ca9-bdc4-8254e1662cb0" \ --name "LoggingConfigsForSensors"

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指AWS 南中的使用 IoT Greengrass 記錄進行監視

下列程式碼範例會示範如何使用update-resource-definition

AWS CLI

若要更新資源定義的名稱

下列update-resource-definition範例會更新指定資源定義的名稱。如果要變更資源的詳細資訊,請使用create-resource-definition-version指令建立新版本。

aws greengrass update-resource-definition \ --resource-definition-id "c8bb9ebc-c3fd-40a4-9c6a-568d75569d38" \ --name GreengrassConnectorResources

此命令不會產生輸出。

如需詳細資訊,請參閱 AWS IoT Greengrass 開發人員指南中的使用 Lambda 函數和連接器存取本機資源。

下列程式碼範例會示範如何使用update-subscription-definition

AWS CLI

若要更新訂閱定義的名稱

下列update-subscription-definition範例會更新指定訂閱定義的名稱。如果您要變更訂閱的詳細資料,請使用create-subscription-definition-version指令建立新版本。

aws greengrass update-subscription-definition \ --subscription-definition-id "fa81bc84-3f59-4377-a84b-5d0134da359b" \ --name "ObsoleteSubscription"

此命令不會產生輸出。

如需詳細資訊,請參閱指南中的標題。

下列程式碼範例會示範如何使用update-thing-runtime-configuration

AWS CLI

若要在 Greengrass 核心的執行階段組態中開啟遙測

下列update-thing-runtime-configuration範例會更新 Greengrass 核心的執行階段組態,以開啟遙測。

aws greengrass update-thing-runtime-configuration \ --thing-name SampleGreengrassCore \ --telemetry-configuration {\"Telemetry\":\"On\"}

此命令不會產生輸出。

如需詳細資訊,請參AWS IoT Greengrass 開發人員指南中的設定遙測設定。