

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

# 设置 LTS 资格认证先决条件
<a name="lts-idt-dev-tester-prereqs"></a>

本节介绍使用测试微控制器的 AWS IoT Device Tester先决条件。

## FreeRTOS 资格认证准备
<a name="idt-preparing-qualification"></a>

**注意**  
AWS IoT Device Tester for FreeRTOS 强烈建议使用最新版本的 FreerTOS-LTS 版本的最新补丁版本。

IDT for FRQ 2.0 是 FreeRTOS 的资格认证计划。在运行 IDT FRQ 2.0 进行资格认证之前，您必须完成《FreeRTOS 资格认证指南》[https://docs.aws.amazon.com/freertos/latest/qualificationguide/freertos-qualification.html](https://docs.aws.amazon.com/freertos/latest/qualificationguide/freertos-qualification.html)主板资格认证。要移植库、测试和设置 `manifest.yml`，请参阅《FreeRTOS 移植指南》中的 [FreeRTOS 库移植](https://docs.aws.amazon.com/freertos/latest/portingguide/afr-porting.html)。**FRQ 2.0 包含不同的资格认证流程。有关详细信息，请参阅《FreeRTOS 资格认证指南》中的**[资格认证最新更改](https://docs.aws.amazon.com/freertos/latest/qualificationguide/latest-changes.html)。

必须存在 [FreeRTOS-Libraries-Integration-Tests](https://github.com/FreeRTOS/FreeRTOS-Libraries-Integration-Tests) 存储库才能运行 IDT。有关如何克隆此存储库并将其移植到源项目的信息，请参阅 [README.md](https://github.com/FreeRTOS/FreeRTOS-Libraries-Integration-Tests/blob/main/README.md)。 FreeRTOS-Libraries-Integration-Tests必须包含`manifest.yml`位于项目根目录中的，IDT 才能运行。

**注意**  
IDT 取决于 `UNITY_OUTPUT_CHAR` 的测试存储库的实现。测试输出日志和设备日志不得相互交错。有关更多详细信息，请参阅《FreeRTOS 移植指南》中的[实现库日志记录宏](https://docs.aws.amazon.com/freertos/latest/portingguide/afr-library-logging-macros.html)部分。**

## 下载适用于 FreeRTOS 的 IDT
<a name="idt-download-dev-tester-afr"></a>

为了执行资格认证测试，FreeRTOS 的每个版本都有对应的适用于 FreeRTOS 的 IDT 版本。从 FreeRTOS 支持的版本中下载适用于 FreeRTOS 的 IDT [的相应版本](https://docs.aws.amazon.com/freertos/latest/userguide/dev-test-versions-afr.html)。 AWS IoT Device Tester 

将适用于 FreeRTOS 的 IDT 提取到文件系统上您具有读写权限的位置。由于 Microsoft Windows 对路径长度具有字符数限制，因此将适用于 FreeRTOS 的 IDT 提取到根目录，如 `C:\` 或 `D:\`。

**注意**  
多个用户不得从共享位置（如 NFS 目录或 Windows 网络共享文件夹）运行 IDT。这会会导致崩溃或数据损坏。我们建议您将 IDT 包解压缩到本地驱动器。

## 下载 Git
<a name="idt-download-git"></a>

作为先决条件，IDT 必须安装 Git 才能确保源代码的完整性。

按照[GitHub](https://github.com/git-guides/install-git)指南中的说明安装 Git。要验证当前安装的 Git 版本，请在终端输入命令 `git --version`。

**警告**  
IDT 使用 Git 来匹配目录的干净或占用状态。如果未安装 Git，`FreeRTOSIntegrity` 测试组要么会失败，要么会无法按预期运行。如果 IDT 返回 `git executable not found` 或 `git command not found` 之类的错误，请安装或重新安装 Git，然后重试。

**Topics**
+ [FreeRTOS 资格认证准备](#idt-preparing-qualification)
+ [下载适用于 FreeRTOS 的 IDT](#idt-download-dev-tester-afr)
+ [下载 Git](#idt-download-git)
+ [创建一个 AWS 账户](#lts-config-aws-account)
+ [AWS IoT Device Tester 托管策略](#managed-policy)
+ [（可选）安装 AWS Command Line Interface](#install-cli)

## 创建一个 AWS 账户
<a name="lts-config-aws-account"></a>

**注意**  
只有以下内容支持完整的 IDT 资格套件 AWS 区域   
美国东部（弗吉尼亚州北部）
 美国西部（俄勒冈） 
亚太地区（东京） 
欧洲地区（爱尔兰） 

为了测试您的设备，适用于 FreeRTOS 的 IDT 会创建诸如 AWS IoT 东西、FreeRTOS 组和 Lambda 函数之类的资源。要创建这些资源，IDT for FreeRTOS 需要您创建和配置 AWS 一个账户，以及一项授予 IDT for FreeRTOS 在运行测试时代表您访问资源的权限的 IAM 策略。

以下步骤用于创建和配置您的 AWS 账户。

1. 如果您已经有一个 AWS 帐户，请跳到下一步。创建一个 [AWS 账户](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/)。

1. 按照[创建 IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html)中的步骤操作。此时请勿添加权限或策略。

1. 要运行 OTA 资格认证测试，请转至步骤 4。否则，请转到步骤 5。

1.  将 OTA IAM 权限内联策略附加到您的 IAM 角色。

   1. 
**重要**  
 以下策略模板授予创建角色、创建策略和将策略附加到角色的 IDT 权限。适用于 FreeRTOS 的 IDT 将这些权限用于创建角色的测试。尽管策略模板不向用户提供管理员权限，但这些权限可用于获得对您 AWS 账户的管理员访问权限。

   1.  执行以下步骤，将必要权限附加到您的 IAM 角色：

      1. 在**权限**页面上，请选择**添加权限**。

      1. 选择**创建内联策略**。

      1. 选择 **JSON** 选项卡，然后将以下权限复制到 **JSON** 文本框中。如果您不在中国区域，请使用**大多数区域**下的模板。如果您在中国区域，请使用**北京和宁夏区域**下的模板。

------
#### [ Most Regions ]

------
#### [ JSON ]

****  

         ```
         {
             "Version":"2012-10-17",		 	 	 
             "Statement": [
                 {
                     "Effect": "Allow",
                     "Action": "iotdeviceadvisor:*",
                     "Resource": [
                         "arn:aws:iotdeviceadvisor:*:*:suiterun/*/*",
                         "arn:aws:iotdeviceadvisor:*:*:suitedefinition/*"
                     ]
                 },
                 {
                     "Effect": "Allow",
                     "Action": "iam:PassRole",
                     "Resource": "arn:aws:iam::*:role/idt*",
                     "Condition": {
                         "StringEquals": {
                             "iam:PassedToService": "iotdeviceadvisor.amazonaws.com"
                         }
                     }
                 },
                 {
                     "Effect": "Allow",
                     "Action": [
                         "execute-api:Invoke*",
                         "iam:ListRoles",
                         "iot:Connect",  
                         "iot:CreateJob",
                         "iot:DeleteJob",
                         "iot:DescribeCertificate", 
                         "iot:DescribeEndpoint",
                         "iot:DescribeJobExecution",
                         "iot:DescribeJob",                                 
                         "iot:DescribeThing",
                         "iot:GetPolicy",
                         "iot:ListAttachedPolicies",
                         "iot:ListCertificates",
                         "iot:ListPrincipalPolicies",
                         "iot:ListThingPrincipals",
                         "iot:ListThings",
                         "iot:Publish",    
                         "iot:UpdateThingShadow",                
                         "logs:CreateLogGroup",
                         "logs:CreateLogStream",
                         "logs:DescribeLogGroups",
                         "logs:DescribeLogStreams",
                         "logs:PutLogEvents",
                         "logs:PutRetentionPolicy"
                     ],
                     "Resource": "*"
                 },
                 {
                     "Effect": "Allow",
                     "Action": "iotdeviceadvisor:*",
                     "Resource": "*"
                 },
                 {
                     "Effect": "Allow",
                     "Action": "logs:DeleteLogGroup",
                     "Resource": "arn:aws:logs:*:*:log-group:/aws/iot/deviceadvisor/*"
                 },
                 {
                     "Effect": "Allow",
                     "Action": "logs:GetLogEvents",
                     "Resource": "arn:aws:logs:*:*:log-group:/aws/iot/deviceadvisor/*:log-stream:*"
                 },
                 {
                     "Effect": "Allow",
                     "Action": [
                         "iam:CreatePolicy",
                         "iam:DetachRolePolicy",
                         "iam:DeleteRolePolicy",
                         "iam:DeletePolicy",
                         "iam:CreateRole",
                         "iam:DeleteRole",
                         "iam:AttachRolePolicy"
                     ],
                     "Resource": [
                         "arn:aws:iam::*:policy/idt*",
                         "arn:aws:iam::*:role/idt*"
                     ]
                 },
                 {
                     "Effect": "Allow",
                     "Action": [
                         "ssm:GetParameters"
                     ],
                     "Resource": [
                         "arn:aws:ssm:*::parameter/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
                     ]
                 },
                 {
                     "Effect": "Allow",
                     "Action": [
                         "ec2:DescribeInstances",
                         "ec2:RunInstances",
                         "ec2:CreateSecurityGroup",
                         "ec2:CreateTags",
                         "ec2:DeleteTags"
                     ],
                     "Resource": [
                         "*"
                     ]
                 },
                 {
                     "Effect": "Allow",
                     "Action": [
                         "ec2:CreateKeyPair",
                         "ec2:DeleteKeyPair"
                     ],
                     "Resource": [
                         "arn:aws:ec2:*:*:key-pair/idt-ec2-ssh-key-*"
                     ]
                 },
                 {
                     "Effect": "Allow",
                     "Condition": {
                         "StringEqualsIgnoreCase": {
                             "aws:ResourceTag/Owner": "IoTDeviceTester"
                         }
                     },
                     "Action": [
                         "ec2:TerminateInstances",
                         "ec2:DeleteSecurityGroup",
                         "ec2:AuthorizeSecurityGroupIngress",
                         "ec2:RevokeSecurityGroupIngress"
                     ],
                     "Resource": [
                         "*"
                     ]
                 }
             ]
         }
         ```

------

------
#### [ Beijing and Ningxia Regions ]

         以下策略模板可在北京和宁夏区域中使用。

------

      1. 完成后，选择**查看策略**。

      1. 输入**IDTFreeRTOSIAMPermissions**作为策略名称。

      1. 选择**创建策略**。

1.  将**AWSIoTDeviceTesterForFreeRTOSFull访问权限**授予您的 IAM 角色。

   1. 将必要的权限附加到您的 IAM 角色：

      1. 在**权限**页面上，请选择**添加权限**。

      1. 选择**附加策略**。

      1. 搜索**AWSIoTDeviceTesterForFreeRTOSFull访问**策略。选中该复选框。

   1. 选择**添加权限**。

1. IDT 的导出凭证。有关详细信息，请参阅[获取用于 CLI 访问的 IAM 角色凭证](https://docs.aws.amazon.com/singlesignon/latest/userguide/howtogetcredentials.html)。

## AWS IoT Device Tester 托管策略
<a name="managed-policy"></a>

`AWSIoTDeviceTesterForFreeRTOSFullAccess`托管策略包含版本检查、auto update 功能和指标收集的以下 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 予下载测试套件更新的权限。
+ `iot-device-tester:SendMetrics`

  授 AWS 予收集 AWS IoT Device Tester 内部使用情况指标的权限。

## （可选）安装 AWS Command Line Interface
<a name="install-cli"></a>

您可能更喜欢使用 AWS CLI 来执行某些操作。如果您没有安装 AWS CLI ，请按照[安装 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) 中的说明执行操作。

通过**aws configure**从命令行运行来为要使用的 AWS 区域进行配置。 AWS CLI [有关支持 IDT for FreeRTOS 的 AWS 区域的信息，AWS 请参阅区域和终端节点。](https://docs.aws.amazon.com/general/latest/gr/rande.html#amazon-freertos-ota-control)有关 **aws configure** 的更多信息，请参阅[使用 **aws configure** 进行快速配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config)。