

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

# 執行 AWS IoT Greengrass 資格套件的先決條件
<a name="dev-tst-prereqs"></a>

本節說明使用 AWS IoT Device Tester (IDT) 的先決條件 AWS IoT Greengrass。

## 下載 AWS IoT Device Tester 適用於 的最新版本 AWS IoT Greengrass
<a name="install-dev-tst-gg"></a>

下載[最新版本](idt-programmatic-download.md)的 IDT，並將軟體解壓縮到檔案系統上具有讀取/寫入許可的位置 (*<device-tester-extract-location>*)。

**注意**  
<a name="unzip-package-to-local-drive"></a>IDT 不支援由多位使用者從共用位置執行，例如 NFS 目錄或 Windows 網路共用資料夾。我們建議您將 IDT 套件解壓縮到本機磁碟機，並在本機工作站上執行 IDT 二進位檔。  
Windows 的路徑長度限制為 260 個字元。如果您使用的是 Windows，請將 IDT 解壓縮到根目錄，例如 `C:\ ` 或 `D:\`，使路徑保持在 260 個字元的限制以下。

## 下載 AWS IoT Greengrass 軟體
<a name="config-gg"></a>

IDT for AWS IoT Greengrass V2 會測試您的裝置與特定 版本的相容性 AWS IoT Greengrass。執行下列命令，將 AWS IoT Greengrass Core 軟體下載至名為 的檔案`aws.greengrass.nucleus.zip`。將 *版本*取代為 IDT [版本的支援核元件](dev-test-versions.md)版本。

------
#### [ Linux or Unix ]

```
curl -s https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-version.zip > aws.greengrass.nucleus.zip
```

------
#### [ Windows Command Prompt (CMD) ]

```
curl -s https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-version.zip > aws.greengrass.nucleus.zip
```

------
#### [ PowerShell ]

```
iwr -Uri https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-version.zip -OutFile aws.greengrass.nucleus.zip
```

------

將下載`aws.greengrass.nucleus.zip`的檔案放在 `<device-tester-extract-location>/products/` 資料夾中。

**注意**  
請勿將相同作業系統和架構的多個檔案放在這個目錄中。

## 建立和設定 AWS 帳戶
<a name="config-aws-account-for-idt"></a>

您必須先執行下列步驟，才能使用 AWS IoT Device Tester for AWS IoT Greengrass V2：

1. [設定 AWS 帳戶。](#create-aws-account-for-idt)如果您已有 AWS 帳戶，請跳到步驟 2。

1. [設定 IDT 的許可。](#configure-idt-permissions)

這些帳戶許可允許 IDT 代表您存取 AWS 服務和建立 AWS 資源，例如 AWS IoT 物件和 AWS IoT Greengrass 元件。

<a name="idt-aws-credentials"></a>為了建立這些資源，IDT for AWS IoT Greengrass V2 會使用`config.json`檔案中設定的 AWS 登入資料，代表您進行 API 呼叫。系統會在測試期間的不同時間點內佈建這些資源。

**注意**  
雖然大多數測試都符合 [AWS 免費方案](https://aws.amazon.com/free)的資格，但您必須在註冊 時提供信用卡 AWS 帳戶。如需詳細資訊，請參閱[如果我的帳戶適用於免費方案，為何需要付款方式？](https://aws.amazon.com/premiumsupport/knowledge-center/free-tier-payment-method/)。

### 步驟 1：設定 AWS 帳戶
<a name="create-aws-account-for-idt"></a>

在此步驟中，建立和設定 AWS 帳戶。如果您已擁有 AWS 帳戶，請跳到 [步驟 2：設定 IDT 的許可](#configure-idt-permissions)。

如果您沒有 AWS 帳戶，請完成下列步驟來建立一個。

**註冊 AWS 帳戶**

1. 開啟 [https://portal.aws.amazon.com/billing/signup](https://portal.aws.amazon.com/billing/signup)。

1. 請遵循線上指示進行。

   部分註冊程序需接收來電或簡訊，並在電話鍵盤輸入驗證碼。

   當您註冊 時 AWS 帳戶，*AWS 帳戶根使用者*會建立 。根使用者有權存取該帳戶中的所有 AWS 服務 和資源。作為安全最佳實務，請將管理存取權指派給使用者，並且僅使用根使用者來執行[需要根使用者存取權的任務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html#root-user-tasks)。

若要建立管理員使用者，請選擇下列其中一個選項。


****  

| 選擇一種管理管理員的方式 | 到 | 根據 | 您也可以 | 
| --- | --- | --- | --- | 
| 在 IAM Identity Center (建議) | 使用短期憑證存取 AWS。這與安全性最佳實務一致。有關最佳實務的資訊，請參閱 *IAM 使用者指南*中的 [IAM 安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-users-federation-idp)。 | 請遵循 AWS IAM Identity Center 使用者指南的[入門](https://docs.aws.amazon.com//singlesignon/latest/userguide/getting-started.html)中的說明。 | 在 AWS Command Line Interface 使用者指南中設定 [AWS CLI 以使用 來設定 AWS IAM Identity Center](https://docs.aws.amazon.com//cli/latest/userguide/cli-configure-sso.html)程式設計存取。 | 
| 在 IAM 中 (不建議使用) | 使用長期憑證存取 AWS。 | 請遵循《IAM 使用者指南》中[建立 IAM 使用者以進行緊急存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started-emergency-iam-user.html) 的指示。 | 請依照《IAM 使用者指南》中的[管理 IAM 使用者的存取金鑰](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_credentials_access-keys.html)設定以程式設計方式存取。 | 

### 步驟 2：設定 IDT 的許可
<a name="configure-idt-permissions"></a>

在此步驟中，設定 IDT for AWS IoT Greengrass V2 用來執行測試和收集 IDT 用量資料的許可。您可以使用 [AWS 管理主控台](#configure-idt-permissions-console)或 [AWS Command Line Interface (AWS CLI)](#configure-idt-permissions-cli) 來建立 IAM 政策和 IDT 的測試使用者，然後將政策連接到使用者。如果您已為 IDT 建立測試使用者，請跳至 [設定您的裝置以執行 IDT 測試](device-config-setup.md)。

#### 設定 IDT (主控台) 的許可
<a name="configure-idt-permissions-console"></a>

1. 登入 [IAM 主控台](https://console.aws.amazon.com/iam)。

1. 建立客戶受管政策，該政策授與建立具有特定許可之角色的許可。

   1. 在導覽窗格中，選擇**政策**，然後選擇**建立政策**。

   1. 如果您不是使用 PreInstalled，請在 **JSON** 索引標籤上，將預留位置內容取代為下列政策。如果您使用的是 PreInstalled，請繼續下列步驟。

      ```
      <a name="customer-managed-policy-cli"></a>{
          "Version":"2012-10-17",		 	 	 
          "Statement":[
          {
            "Sid":"passRoleForResources",
            "Effect":"Allow",
            "Action":"iam:PassRole",
            "Resource":"arn:aws:iam::*:role/idt-*",
            "Condition":{
              "StringEquals":{
                "iam:PassedToService":[
                  "iot.amazonaws.com",
                  "lambda.amazonaws.com",
                  "greengrass.amazonaws.com"
                ]
              }
            }
          },
          {
            "Sid":"lambdaResources",
            "Effect":"Allow",
            "Action":[
              "lambda:CreateFunction",
              "lambda:PublishVersion",
              "lambda:DeleteFunction",
              "lambda:GetFunction"
            ],
            "Resource":[
              "arn:aws:lambda:*:*:function:idt-*"
            ]
          },
          {
            "Sid":"iotResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateThing",
              "iot:DeleteThing",
              "iot:DescribeThing",
              "iot:CreateThingGroup",
              "iot:DeleteThingGroup",
              "iot:DescribeThingGroup",
              "iot:AddThingToThingGroup",
              "iot:RemoveThingFromThingGroup",
              "iot:AttachThingPrincipal",
              "iot:DetachThingPrincipal",
              "iot:UpdateCertificate",
              "iot:DeleteCertificate",
              "iot:CreatePolicy",
              "iot:AttachPolicy",
              "iot:DetachPolicy",
              "iot:DeletePolicy",
              "iot:GetPolicy",
              "iot:Publish",
              "iot:TagResource",
              "iot:ListThingPrincipals",
              "iot:ListAttachedPolicies",
              "iot:ListTargetsForPolicy",
              "iot:ListThingGroupsForThing",
              "iot:ListThingsInThingGroup",
              "iot:CreateJob",
              "iot:DescribeJob",
              "iot:DescribeJobExecution",
              "iot:CancelJob"
            ],
            "Resource":[
              "arn:aws:iot:*:*:thing/idt-*",
              "arn:aws:iot:*:*:thinggroup/idt-*",
              "arn:aws:iot:*:*:policy/idt-*",
              "arn:aws:iot:*:*:cert/*",
              "arn:aws:iot:*:*:topic/idt-*",
              "arn:aws:iot:*:*:job/*"
            ]
          },
          {
            "Sid":"s3Resources",
            "Effect":"Allow",
            "Action":[
              "s3:GetObject",
              "s3:PutObject",
              "s3:DeleteObjectVersion",
              "s3:DeleteObject",
              "s3:CreateBucket",
              "s3:ListBucket",
              "s3:ListBucketVersions",
              "s3:DeleteBucket",
              "s3:PutObjectTagging",
              "s3:PutBucketTagging"
            ],
            "Resource":"arn:aws:s3::*:idt-*"
          },
          {
            "Sid":"roleAliasResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateRoleAlias",
              "iot:DescribeRoleAlias",
              "iot:DeleteRoleAlias",
              "iot:TagResource",
              "iam:GetRole"
            ],
            "Resource":[
              "arn:aws:iot:*:*:rolealias/idt-*",
              "arn:aws:iam::*:role/idt-*"
            ]
          },
          {
            "Sid":"idtExecuteAndCollectMetrics",
            "Effect":"Allow",
            "Action":[
              "iot-device-tester:SendMetrics",
              "iot-device-tester:SupportedVersion",
              "iot-device-tester:LatestIdt",
              "iot-device-tester:CheckVersion",
              "iot-device-tester:DownloadTestSuite"
            ],
            "Resource":"*"
          },
          {
            "Sid":"genericResources",
            "Effect":"Allow",
            "Action":[
              "greengrass:*",
              "iot:GetThingShadow",
              "iot:UpdateThingShadow",
              "iot:ListThings",
              "iot:DescribeEndpoint",
              "iot:CreateKeysAndCertificate"
            ],
            "Resource":"*"
          },
          {
            "Sid":"iamResourcesUpdate",
            "Effect":"Allow",
            "Action":[
              "iam:CreateRole",
              "iam:DeleteRole",
              "iam:CreatePolicy",
              "iam:DeletePolicy",
              "iam:AttachRolePolicy",
              "iam:DetachRolePolicy",
              "iam:TagRole",
              "iam:TagPolicy",
              "iam:GetPolicy",
              "iam:ListAttachedRolePolicies",
              "iam:ListEntitiesForPolicy"
            ],
            "Resource":[
              "arn:aws:iam::*:role/idt-*",
              "arn:aws:iam::*:policy/idt-*"
            ]
          }
        ]
      }
      ```

   1. 如果您使用的是 PreInstalled，請在 **JSON** 標籤上，將預留位置內容取代為下列政策。請確定您：
      + 將 `iotResources`陳述式中的 *thingName* 和 *thingGroup* 取代為測試裝置 (DUT) 上 Greengrass 安裝期間建立的物件名稱和物件群組，以新增許可。
      + 將 `roleAliasResources` 陳述式和 `passRoleForResources`陳述式中的 *passRole* 和 *roleAlias* 取代為 DUT 上 Greengrass 安裝期間建立的角色。

      ```
      <a name="customer-managed-policy-cli"></a>{
          "Version":"2012-10-17",		 	 	 
          "Statement":[
          {
            "Sid":"passRoleForResources",
            "Effect":"Allow",
            "Action":"iam:PassRole",
            "Resource":"arn:aws:iam::*:role/passRole",
            "Condition":{
              "StringEquals":{
                "iam:PassedToService":[
                  "iot.amazonaws.com",
                  "lambda.amazonaws.com",
                  "greengrass.amazonaws.com"
                ]
              }
            }
          },
          {
            "Sid":"lambdaResources",
            "Effect":"Allow",
            "Action":[
              "lambda:CreateFunction",
              "lambda:PublishVersion",
              "lambda:DeleteFunction",
              "lambda:GetFunction"
            ],
            "Resource":[
              "arn:aws:lambda:*:*:function:idt-*"
            ]
          },
          {
            "Sid":"iotResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateThing",
              "iot:DeleteThing",
              "iot:DescribeThing",
              "iot:CreateThingGroup",
              "iot:DeleteThingGroup",
              "iot:DescribeThingGroup",
              "iot:AddThingToThingGroup",
              "iot:RemoveThingFromThingGroup",
              "iot:AttachThingPrincipal",
              "iot:DetachThingPrincipal",
              "iot:UpdateCertificate",
              "iot:DeleteCertificate",
              "iot:CreatePolicy",
              "iot:AttachPolicy",
              "iot:DetachPolicy",
              "iot:DeletePolicy",
              "iot:GetPolicy",
              "iot:Publish",
              "iot:TagResource",
              "iot:ListThingPrincipals",
              "iot:ListAttachedPolicies",
              "iot:ListTargetsForPolicy",
              "iot:ListThingGroupsForThing",
              "iot:ListThingsInThingGroup",
              "iot:CreateJob",
              "iot:DescribeJob",
              "iot:DescribeJobExecution",
              "iot:CancelJob"
            ],
            "Resource":[
              "arn:aws:iot:*:*:thing/thingName",
              "arn:aws:iot:*:*:thinggroup/thingGroup",
              "arn:aws:iot:*:*:policy/idt-*",
              "arn:aws:iot:*:*:cert/*",
              "arn:aws:iot:*:*:topic/idt-*",
              "arn:aws:iot:*:*:job/*"
            ]
          },
          {
            "Sid":"s3Resources",
            "Effect":"Allow",
            "Action":[
              "s3:GetObject",
              "s3:PutObject",
              "s3:DeleteObjectVersion",
              "s3:DeleteObject",
              "s3:CreateBucket",
              "s3:ListBucket",
              "s3:ListBucketVersions",
              "s3:DeleteBucket",
              "s3:PutObjectTagging",
              "s3:PutBucketTagging"
            ],
            "Resource":"arn:aws:s3::*:idt-*"
          },
          {
            "Sid":"roleAliasResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateRoleAlias",
              "iot:DescribeRoleAlias",
              "iot:DeleteRoleAlias",
              "iot:TagResource",
              "iam:GetRole"
            ],
            "Resource":[
              "arn:aws:iot:*:*:rolealias/roleAlias",
              "arn:aws:iam::*:role/idt-*"
            ]
          },
          {
            "Sid":"idtExecuteAndCollectMetrics",
            "Effect":"Allow",
            "Action":[
              "iot-device-tester:SendMetrics",
              "iot-device-tester:SupportedVersion",
              "iot-device-tester:LatestIdt",
              "iot-device-tester:CheckVersion",
              "iot-device-tester:DownloadTestSuite"
            ],
            "Resource":"*"
          },
          {
            "Sid":"genericResources",
            "Effect":"Allow",
            "Action":[
              "greengrass:*",
              "iot:GetThingShadow",
              "iot:UpdateThingShadow",
              "iot:ListThings",
              "iot:DescribeEndpoint",
              "iot:CreateKeysAndCertificate"
            ],
            "Resource":"*"
          },
          {
            "Sid":"iamResourcesUpdate",
            "Effect":"Allow",
            "Action":[
              "iam:CreateRole",
              "iam:DeleteRole",
              "iam:CreatePolicy",
              "iam:DeletePolicy",
              "iam:AttachRolePolicy",
              "iam:DetachRolePolicy",
              "iam:TagRole",
              "iam:TagPolicy",
              "iam:GetPolicy",
              "iam:ListAttachedRolePolicies",
              "iam:ListEntitiesForPolicy"
            ],
            "Resource":[
              "arn:aws:iam::*:role/idt-*",
              "arn:aws:iam::*:policy/idt-*"
            ]
          }
        ]
      }
      ```
**注意**  
如果您想要使用[自訂 IAM 角色做為待測裝置的字符交換角色](set-config.md#custom-token-exchange-role-idt)，請務必更新政策中的 `roleAliasResources` 陳述式和 `passRoleForResources`陳述式，以允許自訂 IAM 角色資源。

   1. 選擇**檢閱政策**。

   1. 對於**名稱**，輸入 **IDTGreengrassIAMPermissions**。在 **Summary (摘要)** 下，檢閱您的政策所授與的許可。

   1. 選擇**建立政策**。

1. 建立 IAM 使用者並連接 IDT for 所需的許可 AWS IoT Greengrass。

   1. 建立 IAM 使用者。請遵循《IAM *使用者指南*》中[建立 IAM 使用者 （主控台）](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_console) 的步驟 1 到 5。

   1. 將許可連接至您的 IAM 使用者：

      1. 在 **Set permissions (設定許可)** 頁面上，選擇 **Attach existing policies directly (直接連接現有的政策)**。

      1. 搜尋您在上一個步驟中建立的 **IDTGreengrassIAMPermissions** 政策。選取核取方塊。

   1. 選擇下**一步：標籤**。

   1. 選擇 **Next: Review (下一步：檢閱)** 以檢視選擇的摘要。

   1. 選擇 **Create user** (建立使用者)。

   1. 若要檢視使用者的存取金鑰 (存取金鑰 ID 和私密存取金鑰)，請選擇密碼和存取金鑰旁的 **Show (顯示)**。若要儲存存取金鑰，請選擇 **Download.csv**，並將檔案儲存到安全的位置。您稍後會使用此資訊來設定您的 AWS 登入資料檔案。

1. <a name="aws-account-config-next-steps"></a>下一步：設定您的[實體裝置](device-config-setup.md)。

#### 步驟 2：設定 IDT (AWS CLI) 的許可
<a name="configure-idt-permissions-cli"></a>

1. 如果尚未安裝 ，請在電腦上安裝和設定 AWS CLI 。請遵循*AWS Command Line Interface 《 使用者指南*》中的[安裝 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) 中的步驟。
**注意**  
 AWS CLI 是開放原始碼工具，可用來與 AWS 命令列 Shell 中的 服務互動。

1. 建立客戶受管政策，以授予管理 IDT 和 AWS IoT Greengrass 角色的許可。

   1. 如果您不是使用 PreInstalled，請開啟文字編輯器，並將下列政策內容儲存在 JSON 檔案中。如果您使用的是 PreInstalled，請繼續下列步驟。

      ```
      <a name="customer-managed-policy-cli"></a>{
          "Version":"2012-10-17",		 	 	 
          "Statement":[
          {
            "Sid":"passRoleForResources",
            "Effect":"Allow",
            "Action":"iam:PassRole",
            "Resource":"arn:aws:iam::*:role/idt-*",
            "Condition":{
              "StringEquals":{
                "iam:PassedToService":[
                  "iot.amazonaws.com",
                  "lambda.amazonaws.com",
                  "greengrass.amazonaws.com"
                ]
              }
            }
          },
          {
            "Sid":"lambdaResources",
            "Effect":"Allow",
            "Action":[
              "lambda:CreateFunction",
              "lambda:PublishVersion",
              "lambda:DeleteFunction",
              "lambda:GetFunction"
            ],
            "Resource":[
              "arn:aws:lambda:*:*:function:idt-*"
            ]
          },
          {
            "Sid":"iotResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateThing",
              "iot:DeleteThing",
              "iot:DescribeThing",
              "iot:CreateThingGroup",
              "iot:DeleteThingGroup",
              "iot:DescribeThingGroup",
              "iot:AddThingToThingGroup",
              "iot:RemoveThingFromThingGroup",
              "iot:AttachThingPrincipal",
              "iot:DetachThingPrincipal",
              "iot:UpdateCertificate",
              "iot:DeleteCertificate",
              "iot:CreatePolicy",
              "iot:AttachPolicy",
              "iot:DetachPolicy",
              "iot:DeletePolicy",
              "iot:GetPolicy",
              "iot:Publish",
              "iot:TagResource",
              "iot:ListThingPrincipals",
              "iot:ListAttachedPolicies",
              "iot:ListTargetsForPolicy",
              "iot:ListThingGroupsForThing",
              "iot:ListThingsInThingGroup",
              "iot:CreateJob",
              "iot:DescribeJob",
              "iot:DescribeJobExecution",
              "iot:CancelJob"
            ],
            "Resource":[
              "arn:aws:iot:*:*:thing/idt-*",
              "arn:aws:iot:*:*:thinggroup/idt-*",
              "arn:aws:iot:*:*:policy/idt-*",
              "arn:aws:iot:*:*:cert/*",
              "arn:aws:iot:*:*:topic/idt-*",
              "arn:aws:iot:*:*:job/*"
            ]
          },
          {
            "Sid":"s3Resources",
            "Effect":"Allow",
            "Action":[
              "s3:GetObject",
              "s3:PutObject",
              "s3:DeleteObjectVersion",
              "s3:DeleteObject",
              "s3:CreateBucket",
              "s3:ListBucket",
              "s3:ListBucketVersions",
              "s3:DeleteBucket",
              "s3:PutObjectTagging",
              "s3:PutBucketTagging"
            ],
            "Resource":"arn:aws:s3::*:idt-*"
          },
          {
            "Sid":"roleAliasResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateRoleAlias",
              "iot:DescribeRoleAlias",
              "iot:DeleteRoleAlias",
              "iot:TagResource",
              "iam:GetRole"
            ],
            "Resource":[
              "arn:aws:iot:*:*:rolealias/idt-*",
              "arn:aws:iam::*:role/idt-*"
            ]
          },
          {
            "Sid":"idtExecuteAndCollectMetrics",
            "Effect":"Allow",
            "Action":[
              "iot-device-tester:SendMetrics",
              "iot-device-tester:SupportedVersion",
              "iot-device-tester:LatestIdt",
              "iot-device-tester:CheckVersion",
              "iot-device-tester:DownloadTestSuite"
            ],
            "Resource":"*"
          },
          {
            "Sid":"genericResources",
            "Effect":"Allow",
            "Action":[
              "greengrass:*",
              "iot:GetThingShadow",
              "iot:UpdateThingShadow",
              "iot:ListThings",
              "iot:DescribeEndpoint",
              "iot:CreateKeysAndCertificate"
            ],
            "Resource":"*"
          },
          {
            "Sid":"iamResourcesUpdate",
            "Effect":"Allow",
            "Action":[
              "iam:CreateRole",
              "iam:DeleteRole",
              "iam:CreatePolicy",
              "iam:DeletePolicy",
              "iam:AttachRolePolicy",
              "iam:DetachRolePolicy",
              "iam:TagRole",
              "iam:TagPolicy",
              "iam:GetPolicy",
              "iam:ListAttachedRolePolicies",
              "iam:ListEntitiesForPolicy"
            ],
            "Resource":[
              "arn:aws:iam::*:role/idt-*",
              "arn:aws:iam::*:policy/idt-*"
            ]
          }
        ]
      }
      ```

   1. 如果您使用的是 PreInstalled，請開啟文字編輯器，並將下列政策內容儲存在 JSON 檔案中。請確定您：
      + 在測試裝置 (DUT) 的 Greengrass 安裝期間建立的`iotResources`陳述式中取代 *thingName* 和 *thingGroup*，以新增許可。
      + 將 `roleAliasResources` 陳述式和 `passRoleForResources`陳述式中的 *passRole* 和 *roleAlias* 取代為 DUT 上 Greengrass 安裝期間建立的角色。

      ```
      <a name="customer-managed-policy-cli"></a>{
          "Version":"2012-10-17",		 	 	 
          "Statement":[
          {
            "Sid":"passRoleForResources",
            "Effect":"Allow",
            "Action":"iam:PassRole",
            "Resource":"arn:aws:iam::*:role/passRole",
            "Condition":{
              "StringEquals":{
                "iam:PassedToService":[
                  "iot.amazonaws.com",
                  "lambda.amazonaws.com",
                  "greengrass.amazonaws.com"
                ]
              }
            }
          },
          {
            "Sid":"lambdaResources",
            "Effect":"Allow",
            "Action":[
              "lambda:CreateFunction",
              "lambda:PublishVersion",
              "lambda:DeleteFunction",
              "lambda:GetFunction"
            ],
            "Resource":[
              "arn:aws:lambda:*:*:function:idt-*"
            ]
          },
          {
            "Sid":"iotResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateThing",
              "iot:DeleteThing",
              "iot:DescribeThing",
              "iot:CreateThingGroup",
              "iot:DeleteThingGroup",
              "iot:DescribeThingGroup",
              "iot:AddThingToThingGroup",
              "iot:RemoveThingFromThingGroup",
              "iot:AttachThingPrincipal",
              "iot:DetachThingPrincipal",
              "iot:UpdateCertificate",
              "iot:DeleteCertificate",
              "iot:CreatePolicy",
              "iot:AttachPolicy",
              "iot:DetachPolicy",
              "iot:DeletePolicy",
              "iot:GetPolicy",
              "iot:Publish",
              "iot:TagResource",
              "iot:ListThingPrincipals",
              "iot:ListAttachedPolicies",
              "iot:ListTargetsForPolicy",
              "iot:ListThingGroupsForThing",
              "iot:ListThingsInThingGroup",
              "iot:CreateJob",
              "iot:DescribeJob",
              "iot:DescribeJobExecution",
              "iot:CancelJob"
            ],
            "Resource":[
              "arn:aws:iot:*:*:thing/thingName",
              "arn:aws:iot:*:*:thinggroup/thingGroup",
              "arn:aws:iot:*:*:policy/idt-*",
              "arn:aws:iot:*:*:cert/*",
              "arn:aws:iot:*:*:topic/idt-*",
              "arn:aws:iot:*:*:job/*"
            ]
          },
          {
            "Sid":"s3Resources",
            "Effect":"Allow",
            "Action":[
              "s3:GetObject",
              "s3:PutObject",
              "s3:DeleteObjectVersion",
              "s3:DeleteObject",
              "s3:CreateBucket",
              "s3:ListBucket",
              "s3:ListBucketVersions",
              "s3:DeleteBucket",
              "s3:PutObjectTagging",
              "s3:PutBucketTagging"
            ],
            "Resource":"arn:aws:s3::*:idt-*"
          },
          {
            "Sid":"roleAliasResources",
            "Effect":"Allow",
            "Action":[
              "iot:CreateRoleAlias",
              "iot:DescribeRoleAlias",
              "iot:DeleteRoleAlias",
              "iot:TagResource",
              "iam:GetRole"
            ],
            "Resource":[
              "arn:aws:iot:*:*:rolealias/roleAlias",
              "arn:aws:iam::*:role/idt-*"
            ]
          },
          {
            "Sid":"idtExecuteAndCollectMetrics",
            "Effect":"Allow",
            "Action":[
              "iot-device-tester:SendMetrics",
              "iot-device-tester:SupportedVersion",
              "iot-device-tester:LatestIdt",
              "iot-device-tester:CheckVersion",
              "iot-device-tester:DownloadTestSuite"
            ],
            "Resource":"*"
          },
          {
            "Sid":"genericResources",
            "Effect":"Allow",
            "Action":[
              "greengrass:*",
              "iot:GetThingShadow",
              "iot:UpdateThingShadow",
              "iot:ListThings",
              "iot:DescribeEndpoint",
              "iot:CreateKeysAndCertificate"
            ],
            "Resource":"*"
          },
          {
            "Sid":"iamResourcesUpdate",
            "Effect":"Allow",
            "Action":[
              "iam:CreateRole",
              "iam:DeleteRole",
              "iam:CreatePolicy",
              "iam:DeletePolicy",
              "iam:AttachRolePolicy",
              "iam:DetachRolePolicy",
              "iam:TagRole",
              "iam:TagPolicy",
              "iam:GetPolicy",
              "iam:ListAttachedRolePolicies",
              "iam:ListEntitiesForPolicy"
            ],
            "Resource":[
              "arn:aws:iam::*:role/idt-*",
              "arn:aws:iam::*:policy/idt-*"
            ]
          }
        ]
      }
      ```
**注意**  
如果您想要使用[自訂 IAM 角色做為待測裝置的字符交換角色](set-config.md#custom-token-exchange-role-idt)，請務必更新政策中的 `roleAliasResources` 陳述式和 `passRoleForResources`陳述式，以允許自訂 IAM 角色資源。

   1. 執行下列命令來建立名為 的客戶受管政策`IDTGreengrassIAMPermissions`。`policy.json` 以您在上一個步驟中建立的 JSON 檔案的完整路徑取代 。

      ```
      aws iam create-policy --policy-name IDTGreengrassIAMPermissions --policy-document file://policy.json
      ```

1. 建立 IAM 使用者並連接 IDT for 所需的許可 AWS IoT Greengrass。

   1. 建立 IAM 使用者。在此範例設定中，使用者命名為 `IDTGreengrassUser`。

      ```
      aws iam create-user --user-name IDTGreengrassUser
      ```

   1. 將您在步驟 2 中建立`IDTGreengrassIAMPermissions`的政策連接到您的 IAM 使用者。使用 的 ID 取代 命令中的 *<account-id>* AWS 帳戶。

      ```
      aws iam attach-user-policy --user-name IDTGreengrassUser --policy-arn arn:aws:iam::<account-id>:policy/IDTGreengrassIAMPermissions
      ```

1. 為使用者建立私密存取金鑰。

   ```
   aws iam create-access-key --user-name IDTGreengrassUser
   ```

   將輸出儲存在安全的位置。您稍後會使用此資訊來設定您的 AWS 登入資料檔案。

1. <a name="aws-account-config-next-steps"></a>下一步：設定您的[實體裝置](device-config-setup.md)。

### AWS IoT Device Tester 許可
<a name="gg-idt-managed-policy"></a>

下列政策說明 AWS IoT Device Tester 許可。

AWS IoT Device Tester 需要這些許可才能進行版本檢查和自動更新功能。
+ `iot-device-tester:SupportedVersion`

   AWS IoT Device Tester 准許擷取支援的產品、測試套件和 IDT 版本清單。
+ `iot-device-tester:LatestIdt`

   AWS IoT Device Tester 准許擷取可供下載的最新 IDT 版本。
+ `iot-device-tester:CheckVersion`

   AWS IoT Device Tester 准許檢查 IDT、測試套件和產品的版本相容性。
+ `iot-device-tester:DownloadTestSuite`

   AWS IoT Device Tester 准許下載測試套件更新。

AWS IoT Device Tester 也會針對選用指標報告使用下列許可：
+ `iot-device-tester:SendMetrics`

  准許 AWS 收集有關 AWS IoT Device Tester 內部使用的指標。如果省略此許可，則不會收集這些指標。