

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

# 使用获取 OTA 失败代码 AWS CLI
<a name="ota-failure-codes"></a>

1. 安装和配置 [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)。

1. 运行 `aws configure` 并输入以下信息。

   ```
   $ aws configure
   AWS Access Key ID [None]: AccessID
   AWS Secret Access Key [None]: AccessKey
   Default region name [None]: Region
   Default output format [None]: json
   ```

   有关更多信息，请参阅[使用 `aws configure` 进行快速配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config)。

1. 运行：

   ```
   aws iot describe-job-execution --job-id JobID --thing-name ThingName
   ```

   哪里*JobID*是我们要获取其状态的任务的完整任务 ID 字符串（它在创建 OTA 更新任务时与 OTA 更新任务相关联），也是设备注册为 AWS IoT 的事物名称 *ThingName* AWS IoT

1. 输出如下所示：

   ```
   {
       "execution": {
           "jobId": "AFR_OTA-****************",
           "status": "FAILED",
           "statusDetails": {
               "detailsMap": {
                   "reason": "0xEEEEEEEE: 0xffffffff"
               }
           },
           "thingArn": "arn:aws:iot:Region:AccountID:thing/ThingName",
           "queuedAt": 1569519049.9,
           "startedAt": 1569519052.226,
           "lastUpdatedAt": 1569519052.226,
           "executionNumber": 1,
           "versionNumber": 2
       }
   }
   ```

   在此示例输出中，“`detailsmap`”中的“`reason`”有两个字段：显示为“0xEEEEEEEE”的字段包含 OTA 代理的常规错误代码；显示为“0xffffffff”的字段包含子代码。[ https://docs.aws.amazon.com/freertos/latest/lib-ref/html1/aws\$1\$1ota\$1\$1agent\$18h.html](https://docs.aws.amazon.com/freertos/latest/lib-ref/html1/aws__ota__agent_8h.html) 中列出了通用错误代码。错误代码带有“`kOTA_Err_`”前缀。子代码可以是平台特定的代码，也可以提供有关常规错误的更多详细信息。