

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

# 使用 建立 OTA 更新 AWS CLI
<a name="ota-cli-workflow"></a>

當您使用 AWS CLI 建立 OTA 更新時，您會：

1. 數位簽署您的韌體映像。

1. 建立您數位簽署韌體映像的串流。

1. 啟動 OTA 更新任務。

## 數位簽署您的韌體更新
<a name="ota-sign-cli"></a>

當您使用 AWS CLI 執行 OTA 更新時，您可以使用 的程式碼簽署 AWS IoT，也可以自行簽署韌體更新。如需程式碼簽署支援的密碼編譯簽署和雜湊演算法清單 AWS IoT，請參閱 [ SigningConfigurationOverrides](https://docs.aws.amazon.com/signer/latest/api/API_SigningConfigurationOverrides.html)。如果您想要使用 Code Signing for 不支援的密碼編譯演算法 AWS IoT，您必須先簽署韌體二進位檔，才能將其上傳至 Amazon S3。

### 使用 的程式碼簽署來簽署您的韌體映像 AWS IoT
<a name="ota-sign-csfa"></a>

若要使用 Code Signing for 來簽署韌體映像 AWS IoT，您可以使用其中一個 [AWS SDKs或命令列工具](https://aws.amazon.com/tools/)。如需 程式碼簽署的詳細資訊 AWS IoT，請參閱 [ 程式碼簽署 AWS IoT](https://docs.aws.amazon.com/signer/latest/developerguide/Welcome.html)。

安裝和設定程式碼簽署工具之後，請將未簽署的韌體映像複製到 Amazon S3 儲存貯體，並使用下列 AWS CLI 命令啟動程式碼簽署任務。**put-signing-profile** 命令會建立可重複使用的程式碼簽署描述檔。**start-signing-job** 命令會啟動簽署任務。

```
aws signer put-signing-profile \
    --profile-name your_profile_name \
    --signing-material certificateArn=arn:aws:acm::your-region:your-aws-account-id:certificate/your-certificate-id \
    --platform your-hardware-platform \
    --signing-parameters certname=your_certificate_path_on_device
```

```
aws signer start-signing-job \
    --source 's3={bucketName=your_s3_bucket,key=your_s3_object_key,version=your_s3_object_version_id}' \
    --destination 's3={bucketName=your_destination_bucket}' \
    --profile-name your_profile_name
```

**注意**  
*your-source-bucket-name* 和 *your-destination-bucket-name* 可以是相同的 Amazon S3 儲存貯體。

這些是 **put-signing-profile** 和 **start-signing-job** 命令的參數：

**`source`**  
指定 S3 儲存貯體中未簽署韌體的位置。  
+ `bucketName`：您 S3 儲存貯體的名稱。
+ `key`：您 S3 儲存貯體中韌體的金鑰 (檔案名稱)。
+ `version`：您 S3 儲存貯體中韌體的 S3 版本。這與您的韌體版本不同。您可以瀏覽至 Amazon S3 主控台、選擇儲存貯體，然後在頁面頂端的**版本**旁選擇**顯示**，即可找到它。

**`destination`**  
S3 儲存貯體中已簽署韌體將複製到其裝置上的目的地。此參數的格式與 `source` 參數相同。

**`signing-material`**  
您程式碼簽署憑證的 ARN。當您將憑證匯入 ACM 時，會產生此 ARN。

**`signing-parameters`**  
用於簽署的鍵/值對映射。這些可包含任何您希望在簽署期間使用的資訊。  
當您在建立簽署描述檔以簽署擁有適用於 AWS IoT程式碼簽署的 OTA 更新時，必須採用此參數。

**`platform`**  
您分發 OTA 更新之目標硬體平台的 `platformId`。  
若要傳回可用平台及其 `platformId` 值的清單，請使用 `aws signer list-signing-platforms` 命令。

簽署任務會啟動已簽署的韌體映像，並將其寫入目的地 Amazon S3 儲存貯體。已簽署韌體映像的檔案名稱是 GUID。當您建立串流時，會需要此檔案名稱。您可以瀏覽至 Amazon S3 主控台並選擇儲存貯體來尋找檔案名稱。若您沒有看到具有 GUID 檔案名稱的檔案，請重新整理您的瀏覽器。

此命令會顯示任務 ARN 及任務 ID。您稍後會需要這些值。如需 程式碼簽署的詳細資訊 AWS IoT，請參閱 [程式碼簽署 AWS IoT](https://docs.aws.amazon.com/signer/latest/developerguide/Welcome.html)。

### 手動簽署您的韌體映像
<a name="ota-sign-manual"></a>

以數位方式簽署您的韌體映像，並將已簽章的韌體映像上傳至您的 Amazon S3 儲存貯體。

## 建立您韌體更新的串流
<a name="ota-stream"></a>

串流是可以由裝置使用之資料的抽象介面。串流可以隱藏下列動作的複雜性：存取在不同位置或不同雲端型服務中存放的資料。OTA Update Manager 服務可讓您使用儲存在 Amazon S3 中各種位置的多個資料片段來執行 OTA 更新。

建立 AWS IoT OTA 更新時，您也可以建立包含已簽署韌體更新的串流。建立可識別已簽署韌體映像的 JSON 檔案 (`stream.json`)。JSON 檔案應包含以下內容。

```
[
  {
    "fileId":"your_file_id",
    "s3Location":{
      "bucket":"your_bucket_name",
      "key":"your_s3_object_key"
    }
  }   
]
```

這些是 JSON 檔案中的屬性：

**`fileId`**  
介於 0–255 之間的任意整數，可識別您的韌體映像。

**`s3Location`**  
儲存貯體及用於串流的韌體鍵。    
**`bucket`**  
存放未簽署韌體映像的 Amazon S3 儲存貯體。  
**`key`**  
Amazon S3 儲存貯體中已簽署韌體映像的檔案名稱。您可以查看儲存貯體的內容，在 Amazon S3 主控台中找到此值。  
如果您使用 Code Signing for AWS IoT，則檔案名稱是由 Code Signing for 產生的 GUID AWS IoT。

使用 **create-stream** AWS CLI 命令來建立串流。

```
aws iot create-stream \
    --stream-id your_stream_id \
    --description your_description \
    --files file://stream.json \
    --role-arn your_role_arn
```

以下是 **create-stream** AWS CLI 命令的引數：

**`stream-id`**  
用於識別串流的任意字串。

**`description`**  
串流的選擇性說明。

**`files`**  
一或多個指向 JSON 檔案的參考，JSON 檔案中包含用於串流的韌體映像相關資料。JSON 檔案必須包含以下屬性：    
**`fileId`**  
任意的檔案 ID。  
**`s3Location`**  
儲存貯體名稱，其中存放了已簽署的韌體映像及已簽署韌體映像的鍵 (檔案名稱)。  
**`bucket`**  
存放已簽署韌體映像的 Amazon S3 儲存貯體。  
**`key`**  
已簽署韌體映像的鍵 (檔案名稱)。  
當您使用 的程式碼簽署時 AWS IoT，此金鑰是 GUID。
以下是範例 `stream.json` 檔案。  

```
[
    {
        "fileId":123,
        "s3Location": {
            "bucket":"codesign-ota-bucket",
            "key":"48c67f3c-63bb-4f92-a98a-4ee0fbc2bef6"
        }
    }
]
```

**`role-arn`**  
也授予儲存韌體映像之 Amazon S3 儲存貯體存取權的 [OTA 服務角色](create-service-role.md)。

若要尋找已簽章韌體映像的 Amazon S3 物件金鑰，請使用 **aws signer describe-signing-job --job-id *my-job-id***命令，其中 `my-job-id`是 **create-signing-job** AWS CLI 命令顯示的任務 ID。**describe-signing-job** 命令的輸出包含已簽署韌體映像的鍵。

```
... text deleted for brevity ...
  "signedObject": {
    "s3": {
      "bucketName": "ota-bucket",
      "key": "7309da2c-9111-48ac-8ee4-5a4262af4429"
    }
  }
... text deleted for brevity ...
```

## 建立 OTA 更新
<a name="create-ota-update"></a>

使用 **create-ota-update** AWS CLI 命令來建立 OTA 更新任務。

**注意**  
請不要在您 OTA 更新的任務 ID 中使用任何個人識別資訊 (PII)。個人識別資訊的範例包括：  
名稱。
IP 地址。
電子郵件地址。
位置
銀行詳細資訊。
醫療資訊。

```
aws iot  create-ota-update \
    --ota-update-id value \
    [--description value] \
    --targets value \
    [--protocols value] \
    [--target-selection value] \
    [--aws-job-executions-rollout-config value] \
    [--aws-job-presigned-url-config value] \
    [--aws-job-abort-config value] \
    [--aws-job-timeout-config value] \
    --files value \
    --role-arn value \
    [--additional-parameters value] \
    [--tags value]  \
    [--cli-input-json value] \
    [--generate-cli-skeleton]
```

 `cli-input-json` 格式

```
{
  "otaUpdateId": "string",
  "description": "string",
  "targets": [
    "string"
  ],
  "protocols": [
    "string"
  ],
  "targetSelection": "string",
  "awsJobExecutionsRolloutConfig": {
    "maximumPerMinute": "integer",
    "exponentialRate": {
      "baseRatePerMinute": "integer",
      "incrementFactor": "double",
      "rateIncreaseCriteria": {
        "numberOfNotifiedThings": "integer",
        "numberOfSucceededThings": "integer"
      }
    }
  },
  "awsJobPresignedUrlConfig": {
    "expiresInSec": "long"
  },
  "awsJobAbortConfig": {
    "abortCriteriaList": [
      {
        "failureType": "string",
        "action": "string",
        "thresholdPercentage": "double",
        "minNumberOfExecutedThings": "integer"
      }
    ]
  },
  "awsJobTimeoutConfig": {
    "inProgressTimeoutInMinutes": "long"
  },
  "files": [
    {
      "fileName": "string",
      "fileType": "integer",
      "fileVersion": "string",
      "fileLocation": {
        "stream": {
          "streamId": "string",
          "fileId": "integer"
        },
        "s3Location": {
          "bucket": "string",
          "key": "string",
          "version": "string"
        }
      },
      "codeSigning": {
        "awsSignerJobId": "string",
        "startSigningJobParameter": {
          "signingProfileParameter": {
            "certificateArn": "string",
            "platform": "string",
            "certificatePathOnDevice": "string"
          },
          "signingProfileName": "string",
          "destination": {
            "s3Destination": {
              "bucket": "string",
              "prefix": "string"
            }
          }
        },
        "customCodeSigning": {
          "signature": {
            "inlineDocument": "blob"
          },
          "certificateChain": {
            "certificateName": "string",
            "inlineDocument": "string"
          },
          "hashAlgorithm": "string",
          "signatureAlgorithm": "string"
        }
      },
      "attributes": {
        "string": "string"
      }
    }
  ],
  "roleArn": "string",
  "additionalParameters": {
    "string": "string"
  },
  "tags": [
    {
      "Key": "string",
      "Value": "string"
    }
  ]
}
```


**`cli-input-json` 欄位**  

| 名稱 | 類型 | Description | 
| --- | --- | --- | 
| `otaUpdateId` |  string  (上限：128；下限：1)  | 欲建立的 OTA 更新 ID。 | 
| `description` |  string  (上限：2028)  | OTA 更新的描述。 | 
| `targets` |  列出  | 將目標鎖定於接收 OTA 更新的裝置。 | 
| `protocols` |  列出  |  用來傳輸 OTA 更新映像的通訊協定。有效值為 [HTTP]、[MQTT]、[HTTP, MQTT]。指定 HTTP 和 MQTT 時，目標裝置可以選擇通訊協定。  | 
| `targetSelection` | string |  指定更新是否要持續運作 (CONTINUOUS)，或在指定為目標的所有物件完成更新後視為完成 (SNAPSHOT)。如果是 CONTINUOUS，則在目標中偵測到變更時，更新也可能會運作於物件上。例如，當物件新增至目標群組，更新就會在物件上運作，即使該更新已被原本就在群組中的所有物件完成。有效值：CONTINUOUS \$1 SNAPSHOT。 列舉：CONTINUOUS \$1 SNAPSHOT  | 
| `awsJobExecutionsRolloutConfig` |  | OTA 更新的發行組態。 | 
| `maximumPerMinute` |  integer  (上限：1000；下限：1)  | 每分鐘可啟動的 OTA 更新任務執行數上限。 | 
| `exponentialRate` |  |  任務推展的增加率。此參數可讓您為任務推展定義指數增加率。  | 
| `baseRatePerMinute` |  integer  (上限：1000；下限：1)  |  在任務推展開始時，每分鐘通知待處理任務的最低物件數量。這是推展的初始率。  | 
|   `rateIncreaseCriteria`  |   |  任務啟動增加推展速率的條件。 AWS IoT 最多支援十進位後一個數字 （例如 1.5，但不支援 1.55)。  | 
|   `numberOfNotifiedThings`  |  integer  (下限：1)  |  收到此物件數量通知時，它會啟動推展率的增加。  | 
|   `numberOfSucceededThings`  |  integer  (下限：1)  |  當此物件數量已在其任務執行中成功時，它會啟動推展率的增加。  | 
| `awsJobPresignedUrlConfig` |  |  預先簽章的 URL 之組態資訊。 | 
|   `expiresInSec`  |  long |  預先簽章的 URL 有效時間 (以秒為單位)。有效值為 60 - 3600，預設值為 1800 秒。收到任務文件的請求時，就會產生預先簽章的 URL。  | 
|   `awsJobAbortConfig`  |   |  決定何時及如何停止任務的條件。 | 
|   `abortCriteriaList`  |  列出  |  決定何時及如何停止任務的條件清單。 | 
|   `failureType`  |  string |  可啟動任務停止的任務執行失敗類型。  enum: FAILED \$1 REJECTED \$1 TIMED\$1OUT \$1 ALL  | 
|   `action`  |  string |  啟動任務停止時要採取的任務動作類型。  enum: CANCEL  | 
|   `minNumberOfExecutedThings`  |  integer  (下限：1)  |  在停止任務之前，必須接收任務執行通知的物件數量下限。  | 
|   `awsJobTimeoutConfig`  |   |  指定每個裝置必須完成其任務執行的時間量。任務執行狀態設定為 `IN_PROGRESS` 時，計時器即會開始。在計時器到期之前，如果任務執行狀態未設定為其他結束狀態，就會自動設為 `TIMED_OUT`。  | 
|   `inProgressTimeoutInMinutes`  |  long |  指定此裝置必須完成這項任務執行的時間 (以分鐘為單位)。逾時間隔可介於 1 分鐘到 7 天之間 (1 到 10080 分鐘)。進行中的計時器無法更新，並會套用到任務的所有任務執行。每當任務執行維持在 IN\$1PROGRESS 狀態超過此間隔時，任務執行就會失敗，並切換到結束 `TIMED_OUT` 狀態。  | 
|   `files`  |  列出  |  OTA 更新所串流的檔案。 | 
|   `fileName`  |  string |  檔案名稱。 | 
|   `fileType`  |  integer  範圍 - 上限：255；下限：0  |  您可以在任務文件中包含的整數值，允許您的裝置識別從雲端收到的檔案類型。  | 
|   `fileVersion`  |  string |  檔案版本。 | 
|   `fileLocation`  |   |  已更新韌體的位置。 | 
|   `stream`  |   |  包含 OTA 更新的串流。 | 
|   `streamId`  |  string  (上限：128；下限：1)  |  串流 ID。 | 
|   `fileId`  |  integer  (上限：255；下限：0)  |  與串流建立關聯的檔案 ID。 | 
|   `s3Location`  |   |  S3 中已更新韌體的位置。 | 
|   `bucket`  |  string  (下限：1)  |  S3 儲存貯體。 | 
|   `key`  |  string  (下限：1)  |  S3 金鑰。 | 
|   `version`  |  string |  S3 儲存貯體版本。 | 
|   `codeSigning`  |   |  檔案的代碼簽署方式。 | 
|   `awsSignerJobId`  |  string |  用於簽署檔案所建立的 AWSSignerJob ID。 | 
|   `startSigningJobParameter`  |   |  描述程式碼簽署任務。 | 
|   `signingProfileParameter`  |   |  描述程式碼簽署描述檔。 | 
|   `certificateArn`  |  string |  憑證 ARN。 | 
|   `platform`  |  string |  您裝置的硬體平台。 | 
|   `certificatePathOnDevice`  |  string |  程式碼簽署憑證在您裝置上的位置。 | 
|   `signingProfileName`  |  string |  程式碼簽署描述檔名稱。 | 
|   `destination`  |   |  撰寫程式碼簽章檔案的位置。 | 
|   `s3Destination`  |   |  描述 S3 中已更新韌體的位置。 | 
|   `bucket`  |  string  (下限：1)  |  內含已更新韌體的 S3 儲存貯體。 | 
|   `prefix`  |  string |  S3 字首。 | 
|   `customCodeSigning`  |   |  代碼簽署檔案的自訂方式。 | 
|   `signature`  |   |  檔案的簽章。 | 
|   `inlineDocument`  |  blob |  以 base64 編碼呈現的二進位代碼簽署簽章。 | 
|   `certificateChain`  |   |  憑證鏈。 | 
|   `certificateName`  |  string |  憑證名稱。 | 
|   `inlineDocument`  |  string |  以 base64 編碼呈現的二進位代碼簽署憑證鏈。 | 
|   `hashAlgorithm`  |  string |  用於以代碼簽署檔案的雜湊演算法。 | 
|   `signatureAlgorithm`  |  string |  用於以代碼簽署檔案的簽章演算法。 | 
|   `attributes`  |  映射 |  名稱/屬性對清單。 | 
|   `roleArn`  |  string  (上限：2048；下限：20)  |  授予 Amazon S3、 AWS IoT 工作和 AWS 程式碼簽署資源 AWS IoT 存取權的 IAM 角色，以建立 OTA 更新任務。 | 
|   `additionalParameters`  |  映射 |  其他 OTA 更新參數清單，以名稱/值對表示。 | 
|   `tags`  |  列出  |  用於管理更新的中繼資料。 | 
|   `Key`  |  string  (上限：128；下限：1)  |  標籤的金鑰。 | 
|   `Value`  |  string  (上限：256；下限：1)  |  標籤的值。 | 

Output

```
{
  "otaUpdateId": "string",
  "awsIotJobId": "string",
  "otaUpdateArn": "string",
  "awsIotJobArn": "string",
  "otaUpdateStatus": "string"
}
```


**AWS CLI 輸出欄位**  

|  名稱 |  類型 |  Description | 
| --- | --- | --- | 
|   `otaUpdateId`  |  string  (上限：128；下限：1)  |  OTA 更新 ID。 | 
|   `awsIotJobId`  |  string |  與 OTA 更新相關聯的 AWS IoT 任務 ID。 | 
|   `otaUpdateArn`  |  string |  OTA 更新 ARN。 | 
|   `awsIotJobArn`  |  string |  與 OTA 更新相關聯的 AWS IoT 任務 ARN。 | 
|   `otaUpdateStatus`  |  string |  OTA 更新狀態。  列舉：CREATE\$1PENDING \$1 CREATE\$1IN\$1PROGRESS \$1 CREATE\$1COMPLETE \$1 CREATE\$1FAILED  | 

以下是傳入使用 Code Signing 之 **create-ota-update**命令的 JSON 檔案範例 AWS IoT。

```
[
  {
    "fileName": "firmware.bin",                
    "fileType": 1,
    "fileLocation": {
      "stream": {
        "streamId": "004",                         
        "fileId":123
      }                        
    },
    "codeSigning": {
      "awsSignerJobId": "48c67f3c-63bb-4f92-a98a-4ee0fbc2bef6"     
    }
  }
]
```

以下是傳入 **create-ota-update** AWS CLI 命令的 JSON 檔案範例，該命令使用內嵌檔案來提供自訂程式碼簽署資料。

```
[
  {
    "fileName": "firmware.bin",
    "fileType": 1,
    "fileLocation": {
      "stream": {
        "streamId": "004",
        "fileId": 123
      }
    },
    "codeSigning": {
      "customCodeSigning":{
        "signature":{
          "inlineDocument":"your_signature"
        },
        "certificateChain": {
          "certificateName": "your_certificate_name",
          "inlineDocument":"your_certificate_chain"
        },
        "hashAlgorithm":"your_hash_algorithm",
        "signatureAlgorithm":"your_signature_algorithm"
      }
    }
  }
]
```

以下是傳入 **create-ota-update** AWS CLI 命令的 JSON 檔案範例，允許 FreeRTOS OTA 啟動程式碼簽署任務並建立程式碼簽署設定檔和串流。

```
[
  {
    "fileName": "your_firmware_path_on_device",
    "fileType": 1,
    "fileVersion": "1",
    "fileLocation": {
      "s3Location": {
        "bucket": "your_bucket_name",
        "key": "your_object_key",
        "version": "your_S3_object_version"
      }
    },
    "codeSigning":{
      "startSigningJobParameter":{
        "signingProfileName": "myTestProfile",
        "signingProfileParameter": {
          "certificateArn": "your_certificate_arn",
          "platform": "your_platform_id",
          "certificatePathOnDevice": "certificate_path"
        },
        "destination": {
          "s3Destination": {
            "bucket": "your_destination_bucket"
          }
        }
      }
    }  
  }
]
```

以下是傳入 **create-ota-update** AWS CLI 命令的 JSON 檔案範例，該命令會建立 OTA 更新，以現有設定檔啟動程式碼簽署任務，並使用指定的串流。

```
[
  {
    "fileName": "your_firmware_path_on_device",
    "fileType": 1,
    "fileVersion": "1",
    "fileLocation": {
      "s3Location": {
        "bucket": "your_s3_bucket_name",
        "key": "your_object_key",
        "version": "your_S3_object_version"
      }
    },
    "codeSigning":{
      "startSigningJobParameter":{
        "signingProfileName": "your_unique_profile_name",
        "destination": {
          "s3Destination": {
            "bucket": "your_destination_bucket"
          }
        }
      }
    }  
  }
]
```

以下是傳入 **create-ota-update** AWS CLI 命令的 JSON 檔案範例，允許 FreeRTOS OTA 建立具有現有程式碼簽署任務 ID 的串流。

```
[
  {
    "fileName": "your_firmware_path_on_device",
    "fileType": 1,
    "fileVersion": "1",
    "codeSigning":{
      "awsSignerJobId": "your_signer_job_id"
    }  
  }
]
```

以下是傳入 **create-ota-update** AWS CLI 命令以建立 OTA 更新的 JSON 檔案範例。更新會從指定的 S3 物件建立串流，並使用自訂程式碼簽署。

```
[
  {
    "fileName": "your_firmware_path_on_device",
    "fileType": 1,
    "fileVersion": "1",
    "fileLocation": {
      "s3Location": {
        "bucket": "your_bucket_name",
        "key": "your_object_key",
        "version": "your_S3_object_version"
      }
    },
    "codeSigning":{
      "customCodeSigning": {
        "signature":{
          "inlineDocument":"your_signature"
        },
        "certificateChain": {
          "inlineDocument":"your_certificate_chain",
          "certificateName": "your_certificate_path_on_device"
        },
        "hashAlgorithm":"your_hash_algorithm",
        "signatureAlgorithm":"your_sig_algorithm"
      }
    }  
  }
]
```

## 列出 OTA 更新
<a name="list-ota-updates"></a>

您可以使用 **list-ota-updates** AWS CLI 命令來取得所有 OTA 更新的清單。

```
aws iot list-ota-updates
```

**list-ota-updates** 命令的輸出看起來與以下內容相似。

```
{
  "otaUpdates": [
     
    {
      "otaUpdateId": "my_ota_update2",
      "otaUpdateArn": "arn:aws:iot:us-west-2:123456789012:otaupdate/my_ota_update2",
      "creationDate": 1522778769.042
    },
    {
      "otaUpdateId": "my_ota_update1",
      "otaUpdateArn": "arn:aws:iot:us-west-2:123456789012:otaupdate/my_ota_update1",
      "creationDate": 1522775938.956
    },
    {
      "otaUpdateId": "my_ota_update",
      "otaUpdateArn": "arn:aws:iot:us-west-2:123456789012:otaupdate/my_ota_update",
      "creationDate": 1522775151.031
    }
  ]
}
```

## 取得 OTA 更新的相關資訊
<a name="get-ota-updates"></a>

您可以使用 **get-ota-update** AWS CLI 命令來取得 OTA 更新的建立或刪除狀態。

```
aws iot get-ota-update --ota-update-id your-ota-update-id
```

**get-ota-update** 命令的輸出如下。

```
{ 
    "otaUpdateInfo": { 
        "otaUpdateId": "ota-update-001", 
        "otaUpdateArn": "arn:aws:iot:region:123456789012:otaupdate/ota-update-001", 
        "creationDate": 1575414146.286, 
        "lastModifiedDate": 1575414149.091, 
        "targets": [ 
            "arn:aws:iot:region:123456789012:thing/myDevice" 
        ], 
        "protocols": [ "HTTP" ], 
        "awsJobExecutionsRolloutConfig": { 
            "maximumPerMinute": 0 
        }, 
        "awsJobPresignedUrlConfig": { 
            "expiresInSec": 1800 
        }, 
        "targetSelection": "SNAPSHOT", 
        "otaUpdateFiles": [ 
            { 
                "fileName": "my_firmware.bin", 
                "fileType": 1,
                "fileLocation": { 
                    "s3Location": { 
                        "bucket": "my-bucket", 
                        "key": "my_firmware.bin", 
                        "version": "AvP3bfJC9gyqnwoxPHuTqM5GWENt4iii" 
                    } 
                }, 
                "codeSigning": { 
                    "awsSignerJobId": "b7a55a54-fae5-4d3a-b589-97ed103737c2", 
                    "startSigningJobParameter": { 
                        "signingProfileParameter": {}, 
                        "signingProfileName": "my-profile-name", 
                        "destination": { 
                            "s3Destination": { 
                                "bucket": "some-ota-bucket", 
                                "prefix": "SignedImages/" 
                            } 
                        } 
                    }, 
                    "customCodeSigning": {} 
                } 
            } 
        ], 
        "otaUpdateStatus": "CREATE_COMPLETE", 
        "awsIotJobId": "AFR_OTA-ota-update-001", 
        "awsIotJobArn": "arn:aws:iot:region:123456789012:job/AFR_OTA-ota-update-001" 
    } 
}
```

為 `otaUpdateStatus` 傳回的值包括下列項目：

**`CREATE_PENDING`**  
建立 OTA 更新正在擱置中。

**`CREATE_IN_PROGRESS`**  
正在建立 OTA 更新。

**`CREATE_COMPLETE`**  
已建立 OTA 更新。

**`CREATE_FAILED`**  
建立 OTA 更新失敗。

**`DELETE_IN_PROGRESS`**  
正在刪除 OTA 更新。

**`DELETE_FAILED`**  
刪除 OTA 更新失敗。

**注意**  
若要在 OTA 更新建立後取得其執行狀態，您需要使用 **describe-job-execution** 命令。如需詳細資訊，請參閱[描述任務執行](https://docs.aws.amazon.com/iot/latest/developerguide/manage-job-cli.html#describe-job-execution)。

## 刪除 OTA 相關資料
<a name="delete-ota-data"></a>

目前，您無法使用 AWS IoT 主控台刪除串流或 OTA 更新。您可以使用 AWS CLI 刪除串流、OTA 更新，以及在 OTA 更新期間建立 AWS IoT 的任務。

### 刪除 OTA 串流
<a name="delete-ota-stream"></a>

當您建立使用 MQTT 的 OTA 更新時，您可以使用命令列或 AWS IoT 主控台來建立串流，將韌體分成區塊，以便透過 MQTT 傳送。您可以使用 **delete-stream** AWS CLI 命令刪除此串流，如下列範例所示。

```
aws iot delete-stream --stream-id your_stream_id
```

### 刪除 OTA 更新
<a name="delete-ota-update"></a>

當您建立 OTA 更新時，系統會建立以下項目：
+ OTA 更新任務資料庫中的項目。
+ 執行更新 AWS IoT 的任務。
+ 要更新之每個裝置 AWS IoT 的任務執行。

**delete-ota-update** 命令只會刪除 OTA 更新任務資料庫中的項目。您必須使用 **delete-job** 命令來刪除 AWS IoT 任務。

使用 **delete-ota-update** 命令刪除 OTA 更新。

```
aws iot delete-ota-update --ota-update-id your_ota_update_id
```

**`ota-update-id`**  
欲刪除的 OTA 更新 ID。

**`delete-stream`**  
刪除與 OTA 更新相關聯的串流。

**`force-delete-aws-job`**  
刪除與 OTA 更新相關聯的 AWS IoT 任務。若未設定此標記，並且任務正處於 `In_Progress` 狀態，便不會刪除任務。

### 刪除為 OTA 更新建立的 IoT 任務
<a name="delete-ota-job"></a>

FreeRTOS 會在您建立 OTA 更新時建立 AWS IoT 任務。也會為每個裝置建立任務執行，處理任務。您可以使用 **delete-job** AWS CLI 命令來刪除任務及其相關聯的任務執行。

```
aws iot delete-job --job-id your-job-id --no-force
```

`no-force` 參數會指定僅刪除處於終止狀態 (COMPLETED 或 CANCELLED) 的任務。您可以透過傳遞 `force` 參數，來刪除並未處於終止狀態的任務。如需詳細資訊，請參閱 [DeleteJob API](https://docs.aws.amazon.com/iot/latest/apireference/API_DeleteJob.html)。

**注意**  
刪除任何處於 IN\$1PROGRESS 狀態的任務會插斷任何您裝置上同樣處於 IN\$1PROGRESS 狀態的任務執行，並且可能導致裝置處於不具確定性的狀態。請確保每個執行遭刪除任務的裝置都能復原至已知狀態。

視為任務建立的任務執行數及其他因素而定，刪除任務可能需要數分鐘。刪除任務時，其狀態會是 DELETION\$1IN\$1PROGRESS。嘗試刪除或取消狀態已為 DELETION\$1IN\$1PROGRESS 的任務將會導致錯誤。

您可以利用 **delete-job-execution** 來刪除任務執行。您可能會想要在一小部分的裝置無法處理任務時刪除任務執行。這會刪除單一裝置的任務執行，如下列範例所示。

```
aws iot delete-job-execution --job-id your-job-id --thing-name
                    your-thing-name --execution-number your-job-execution-number --no-force
```

如同 **delete-job** AWS CLI 命令，您可以將 `--force` 參數傳遞至 **delete-job-execution**，以強制刪除任務執行。如需詳細資訊，請參閱 [DeleteJobExecution API](https://docs.aws.amazon.com/iot/latest/apireference/API_DeleteJobExecution.html)。

**注意**  
刪除任何處於 IN\$1PROGRESS 狀態的任務執行會插斷任何您裝置上同樣處於 IN\$1PROGRESS 狀態的任務執行，並且可能導致裝置處於不具確定性的狀態。請確保每個執行遭刪除任務的裝置都能復原至已知狀態。

關於使用 OTA 更新示範應用程式的詳細資訊，請參閱[無線更新示範應用程式](ota-demo.md)。