

# AWS IoT Device Defender 入門
<a name="dd-tutorials"></a>

您可以使用以下教學來運用 AWS IoT Device Defender。

**Topics**
+ [

# 設定
](dd-setting-up.md)
+ [

# 稽核指南
](audit-tutorial.md)
+ [

# ML Detect 指南
](dd-detect-ml-getting-started.md)
+ [

# 自訂您檢視 AWS IoT Device Defender 稽核結果的時間和方式
](dd-suppressions-example.md)

# 設定
<a name="dd-setting-up"></a>

初次使用 AWS IoT Device Defender 之前，請先完成以下作業：

**Topics**
+ [

## 註冊 AWS 帳戶
](#sign-up-for-aws)
+ [

## 建立具有管理存取權的使用者
](#create-an-admin)

## 註冊 AWS 帳戶
<a name="sign-up-for-aws"></a>

如果您還沒有 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)。

AWS註冊程序完成後， 會傳送一封確認電子郵件給您。您可以隨時登錄 [https://aws.amazon.com/](https://aws.amazon.com/) 並選擇**我的帳戶**，以檢視您目前的帳戶活動並管理帳戶。

## 建立具有管理存取權的使用者
<a name="create-an-admin"></a>

當您註冊 AWS 帳戶 之後，請保護您的 AWS 帳戶根使用者，啟用 AWS IAM Identity Center，並建立管理使用者，讓您可以不使用根使用者處理日常作業。

**保護您的 AWS 帳戶根使用者**

1.  選擇**根使用者**並輸入您的 AWS 帳戶電子郵件地址，以帳戶擁有者身分登入 [AWS 管理主控台](https://console.aws.amazon.com/)。在下一頁中，輸入您的密碼。

   如需使用根使用者登入的說明，請參閱 *AWS 登入 使用者指南*中的[以根使用者身分登入](https://docs.aws.amazon.com/signin/latest/userguide/console-sign-in-tutorials.html#introduction-to-root-user-sign-in-tutorial)。

1. 若要在您的根使用者帳戶上啟用多重要素驗證 (MFA)。

   如需指示，請參閱《*IAM 使用者指南*》中的 [Enable a virtual MFA device for your AWS 帳戶 root user (console)](https://docs.aws.amazon.com/IAM/latest/UserGuide/enable-virt-mfa-for-root.html) 一節。

**建立具有管理存取權的使用者**

1. 啟用 IAM Identity Center。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[啟用 AWS IAM Identity Center](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-set-up-for-idc.html)。

1. 在 IAM Identity Center 中，將管理存取權授予使用者。

   若要取得有關使用 IAM Identity Center 目錄 做為身分識別來源的教學課程，請參閱《AWS IAM Identity Center 使用者指南》**中的[以預設 IAM Identity Center 目錄 設定使用者存取權限](https://docs.aws.amazon.com//singlesignon/latest/userguide/quick-start-default-idc.html)。

**以具有管理存取權的使用者身分登入**
+ 若要使用您的 IAM Identity Center 使用者簽署，請使用建立 IAM Identity Center 使用者時傳送至您電子郵件地址的簽署 URL。

  如需有關如何使用 IAM Identity Center 使用者登入的說明，請參閱《AWS 登入 使用者指南》**中的[登入 AWS 存取入口網站](https://docs.aws.amazon.com/signin/latest/userguide/iam-id-center-sign-in-tutorial.html)。

**指派存取權給其他使用者**

1. 在 IAM Identity Center 中，建立一個許可集來遵循套用最低權限的最佳實務。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[建立許可集](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-started-create-a-permission-set.html)。

1. 將使用者指派至群組，然後對該群組指派單一登入存取權。

   如需指示，請參閱《AWS IAM Identity Center 使用者指南》**中的[新增群組](https://docs.aws.amazon.com//singlesignon/latest/userguide/addgroups.html)。

這些任務會建立 AWS 帳戶，以及具備帳戶管理員權限的使用者。

# 稽核指南
<a name="audit-tutorial"></a>

本教學課程提供如何設定週期性稽核、設定警示、檢閱稽核結果，以及緩解稽核問題的指示。

**Topics**
+ [

## 必要條件
](#audit-tutorial-prerequisites)
+ [

## 啟用稽核檢查
](#audit-tutorial-enable-checks)
+ [

## 檢視稽核結果
](#audit-tutorial-view-audit)
+ [

## 建立稽核緩解動作
](#audit-tutorial-mitigation)
+ [

## 將緩和動作套用至您的稽核結果發現項目
](#apply-mitigation-actions)
+ [

## 建立 AWS IoT Device Defender 稽核 IAM 角色 (選用)
](#audit-iam)
+ [

## 啟用 SNS 通知 (選用)
](#audit-tutorial-enable-sns)
+ [

## 設定客戶自管金鑰的許可 (選用)
](#audit-tutorial-cmk-permissions)
+ [

## 啟用記錄 (選用)
](#enable-logging)

## 必要條件
<a name="audit-tutorial-prerequisites"></a>

為了完成本教學，您需要以下項目：
+ AWS 帳戶。如果您沒有此項，請參閱[設定](https://docs.aws.amazon.com/iot/latest/developerguide/dd-setting-up.html)。

## 啟用稽核檢查
<a name="audit-tutorial-enable-checks"></a>

在下列程序中，您啟用稽核檢查，查看帳戶以及裝置設定和政策，以確保安全措施準備就緒。在本教學課程中，我們會指示您啟用所有稽核檢查，但您可以選取您想要的任何檢查。

稽核定價係根據每月的裝置計數 (連接至 AWS IoT 的機群裝置)。因此，使用此功能時，新增或移除稽核檢查不會影響您的每月帳單。

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格中，展開**安全性**並選擇**簡介**。

1. 選擇**自動化 AWS IoT 安全稽核**。稽核檢查會自動開啟。

1. 展開**稽核**並選擇**設定**以檢視您的稽核檢查。請選擇稽核檢查名稱，進一步瞭解稽核檢查的功能。如需稽核檢查的詳細資訊，請參閱[稽核檢查](https://docs.aws.amazon.com/iot/latest/developerguide/device-defender-audit-checks.html)。

1. (選用) 如果您已擁有想使用的角色，請選擇**管理服務許可**，從清單中選擇角色，然後選擇**更新**。

## 檢視稽核結果
<a name="audit-tutorial-view-audit"></a>

下列程序顯示如何檢視您的稽核結果。在本教學課程中，您會看到稽核結果，這些稽核結果來自[啟用稽核檢查](#audit-tutorial-enable-checks)教學課程中設定的稽核檢查。

**檢視稽核結果**

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格中，展開**安全性**、**稽核**，然後選擇**結果**。

1. 選取您想要調查之稽核排程的**名稱**。

1. 在**不合規的檢查**的**緩解**下，選擇資訊按鈕，以取得為何不合規的相關資訊。針對有關如何使不合規檢查成為合規檢查的指示，請參閱 [稽核檢查](device-defender-audit-checks.md)。

## 建立稽核緩解動作
<a name="audit-tutorial-mitigation"></a>

在下列程序中，您將建立 AWS IoT Device Defender 稽核緩解動作來啟用 AWS IoT 記錄。每個稽核檢查都有對應的緩解動作，這些動作會影響您針對要修正的稽核檢查選擇哪種 **Action type** (動作類型)。如需詳細資訊，請參閱[緩解動作](https://docs.aws.amazon.com/iot/latest/developerguide/device-defender-mitigation-actions.html#defender-audit-apply-mitigation-actions.html)。

**使用主 AWS IoT 控台來建立緩解動作**

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格中，展開**安全性**、**偵測**，然後選擇**緩解動作**。

1. 在 **Mitigation Actions** (緩解動作) 頁面上選擇 **Create** (建立)。

1. 在**建立緩解動作**頁面的**動作名稱**，輸入唯一的緩解動作名稱，例如 *EnableErrorLoggingAction*。

1. 針對**動作類型**，選擇**啟用 AWS IoT 記錄**。

1. 在**許可**中，選擇**建立角色**。針對**角色名稱**，使用 *IoTMitigationActionErrorLoggingRole*。然後，選擇 **Create** (建立)。

1. 在**參數**的**用於記錄的角色**，選取 `IoTMitigationActionErrorLoggingRole`。針對 **Log level** (日誌層級)，選擇 `Error`。

1. 選擇**建立**。

## 將緩和動作套用至您的稽核結果發現項目
<a name="apply-mitigation-actions"></a>

下列程序顯示如何將緩解動作套用至您的稽核結果。

**緩解不合規範的稽核結果**

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格中，展開**安全性**、**稽核**，然後選擇**結果**。

1. 選擇您想要回應的稽核結果。

1. 檢查您的結果。

1. 選擇 **Start Mitigation Actions** (開始緩解動作)。

1. 針對**已停用記錄**，選擇您先前建立的緩解動作 `EnableErrorLoggingAction`。您可針對每個不合規結果選取適當的動作來解決問題。

1. 針對**選取原因代碼**，選擇稽核檢查傳回的原因代碼。

1. 選擇**開始任務**。緩解動作可能需要幾分鐘的時間來執行。

**檢查緩和動作是否已運作**

1. 在 AWS IoT 主控台的導覽窗格中，選擇**設定**。

1. 在**服務日誌**中，確認**日誌層級**是 `Error (least verbosity)`。

## 建立 AWS IoT Device Defender 稽核 IAM 角色 (選用)
<a name="audit-iam"></a>

在下列程序中，您建立 AWS IoT Device Defender 稽核 IAM 角色，提供 AWS IoT Device Defender 讀取 AWS IoT 的權限。

**建立 AWS IoT Device Defender 的服務角色 (IAM 主控台)**

1. 登入 AWS 管理主控台，並前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在 IAM 主控台的導覽窗格中，選擇**角色**，然後選擇**建立角色**。

1. 選擇 **AWS 服務** 角色類型。

1. 在**其他 AWS 服務的使用案例**中，選擇 **AWS IoT**，然後選擇 **IoT - Device Defender Audit**。

1. 選擇**下一步**。

1. (選用) 設定[許可界限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)。這是進階功能，可用於服務角色，而不是服務連結的角色。

   展開 **Permissions boundary** (許可界限) 區段，並選擇 **Use a permissions boundary to control the maximum role permissions** (使用許可界限來控制角色許可上限)。IAM 包含您帳戶中的 AWS 受管和客戶受管政策清單。選取用於許可界限的政策，或者選擇 **Create policy** (建立政策) 以開啟新的瀏覽器標籤，並從頭建立新的政策。如需詳細資訊，請參閱《IAM 使用者指南》**中的[建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-start)。在您建立政策後，關閉該標籤並返回您的原始標籤，以選取用於許可界限的政策。

1. 選擇**下一步**。

1. 請輸入角色名稱，以協助您識別此角色的用途。角色名稱在您的 AWS 帳戶 內必須是獨一無二的。它們無法透過大小寫進行區分。例如，您無法建立名為 **PRODROLE** 和 **prodrole** 的角色。因為有各種實體可能會參考此角色，所以建立角色之後，您就無法編輯其名稱。

1. (選用) 在 **Description** (說明) 中，輸入新角色的說明。

1. 在 **Step 1: Select trusted entities** (步驟 1：選取受信任的實體) 或者 **Step 2: Select permissions** (步驟 2：選取許可) 區段中選擇 **Edit** (編輯)，可編輯角色的使用案例和許可。

1. (選用) 藉由連接標籤作為鍵值對，將中繼資料新增至使用者。如需有關在 IAM 中使用標籤的詳細資訊，請參閱《IAM 使用者指南》**中的[標記 IAM 資源](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_tags.html)。

1. 檢閱角色，然後選擇**建立角色**。

## 啟用 SNS 通知 (選用)
<a name="audit-tutorial-enable-sns"></a>

在下列程序中，您可以啟用 Amazon SNS (SNS) 通知，以在稽核識別出任何不合規資源時提醒您。在本教學課程中，您將針對 [啟用稽核檢查](#audit-tutorial-enable-checks) 教學課程中啟用的稽核檢查設定通知。

1. 如果您尚未設定，請依照 AWS 管理主控台 套用政策以存取 SNS。您可依照《*IAM 使用者指南*》中[將政策連接至 IAM 使用者群組](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_groups_manage_attach-policy.html)的指示，選取 **AWSIoTDeviceDefenderPublishFindingsToSNSMitigationAction** 政策以執行此動作。

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格中，展開**安全性**、**稽核**，然後選擇**設定**。

1. 在 **Device Defender 稽核設定**頁面底部，選擇**啟用 SNS 提醒**。

1. 選擇 **Enable** (啟用)。

1. 針對**主題**，選擇**建立新主題**。將主題命名為 *IoTDDNotifications*，然後選擇**建立**。針對**角色**，選擇您在 [建立 AWS IoT Device Defender 稽核 IAM 角色 (選用)](#audit-iam) 建立的角色。

1. 選擇**更新**。

1. 如果您想要透過 Amazon SNS 接收維運平台中的電子郵件或簡訊，請參閱[使用 Amazon Simple Notification Service 傳送使用者通知](https://docs.aws.amazon.com/sns/latest/dg/sns-user-notifications.html)。

## 設定客戶自管金鑰的許可 (選用)
<a name="audit-tutorial-cmk-permissions"></a>

**注意**  
只有在您已選擇加入 AWS IoT Core 的客戶自管金鑰時，才需要此組態。如需 AWS IoT Core 靜態加密的詳細資訊，請參閱 [AWS IoT Core 中的靜態資料加密](https://docs.aws.amazon.com/iot/latest/developerguide/encryption-at-rest.html)。

如果您已針對 AWS IoT 核心靜態加密啟用客戶自管金鑰 (CMK)，則 AWS IoT Device Defender Audit 使用的 IAM 角色需要額外許可權限來解密資料。如果沒有這些許可，您的稽核操作將會失敗。

根據最低權限原則，[https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AWSIoTDeviceDefenderAudit.html](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AWSIoTDeviceDefenderAudit.html) 受管政策不包含設計 `kms:Decrypt` 許可。使用客戶自管金鑰時，您必須手動將這些許可權限新增至稽核角色。

**將 KMS 許可新增至您的 AWS IoT Device Defender 稽核 IAM 角色**

1. 登入 AWS 管理主控台，並前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在導覽窗格中，選擇**角色**，然後搜尋您在 [建立 AWS IoT Device Defender 稽核 IAM 角色 (選用)](#audit-iam) 中建立的角色，或您在設定稽核設定時指定的角色。

1. 選擇角色名稱以開啟其詳細資訊頁面。

1. 在**許可**標籤中，選擇**新增許可**，然後選擇**建立內嵌政策**。

1. 選擇 **JSON** 索引標籤，並輸入下列政策。將 *REGION*、*ACCOUNT\$1ID* 和 *KEY\$1ID* 取代為您的 AWS KMS 金鑰詳細資訊：

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "kms:Decrypt"
         ],
         "Resource": "arn:aws:kms:REGION:ACCOUNT_ID:key/KEY_ID"
       }
     ]
   }
   ```

1. 選擇**下一步**。

1. 針對**政策名稱**，請輸入描述性名稱，例如 **DeviceDefenderAuditKMSDecrypt**。

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

## 啟用記錄 (選用)
<a name="enable-logging"></a>

此程序描述如何啟用 AWS IoT 將資訊記錄至 CloudWatch Logs。這可讓您檢視稽核結果。啟用記錄可能會產生費用。

**啟用記錄**

1. 開啟 [AWS IoT 主控台](https://console.aws.amazon.com/iot)。在導覽窗格選擇**設定**。

1. 在**日誌**中，選擇**管理日誌**。

1. 針對**選取角色**，選擇**建立角色**。將角色命名為 *AWSIoTLoggingRole*，並選擇**建立**。將自動連接政策。

1. 針對**日誌層級**，選擇**除錯 (最詳細層級)**。

1. 選擇**更新**。

# ML Detect 指南
<a name="dd-detect-ml-getting-started"></a>

**注意**  
在下列區域目前未提供 ML Detect：  
亞太地區 (馬來西亞)

在此入門指南中，您可以建立 ML Detect 安全性設定檔，其會使用機器學習 (ML)，根據您裝置的歷史指標資料建立預期行為的模型。當 ML Detect 建立 ML 模型時，您可以監控其進度。在建置 ML 模型之後，您可以持續檢視和調查警示，並緩解已識別的問題。

如需 ML Detect 及其 API 和 CLI 命令的相關資訊，請參閱 [ML Detect](dd-detect-ml.md)。

**Topics**
+ [

## 必要條件
](#ml-detect-prereqs)
+ [

## 如何在主控台中使用 ML Detect
](#dd-detect-ml-console)
+ [

## 如何搭配 CLI 使用 ML Detect
](#dd-detect-ml-cli)

## 必要條件
<a name="ml-detect-prereqs"></a>
+ AWS 帳戶。如果您沒有此項，請參閱[設定](https://docs.aws.amazon.com/iot/latest/developerguide/dd-setting-up.html)。

## 如何在主控台中使用 ML Detect
<a name="dd-detect-ml-console"></a>

**Topics**
+ [

### 啟用 ML Detect
](#enable-ml-detect-console)
+ [

### 監控您的 ML 模型狀態
](#monitor-ml-models-console)
+ [

### 檢閱您的 ML Detect 警示
](#review-ml-alarms-console)
+ [

### 微調您的 ML 警示
](#fine-tune-ml-models-console)
+ [

### 標記警示的驗證狀態
](#mark-your-alarms)
+ [

### 緩解已識別的裝置問題
](#mitigate-ml-issues-console)

### 啟用 ML Detect
<a name="enable-ml-detect-console"></a>

下列程序詳述如何在主控台中設定 ML Detect。

1. 首先，確保您的裝置將建立 [ML Detect 最低需求](dd-detect-ml.md#dd-detect-ml-requirements)中定義的最小必要資料點，以持續訓練和重新整理模型。如需進行資料收集，請確定您的安全性設定檔已連接到目標，該目標可以是物件或物件群組。

1. 在 [AWS IoT 主控台](https://console.aws.amazon.com/iot)的導覽窗格中，展開 **Defend** (防禦)。依序選擇 **Detect** (偵測)、**Security profiles** (安全性設定檔)、**Create security profile** (建立安全性設定檔)、**Create ML anomaly Detect profile** (建立 ML 異常偵測設定檔)。

1. 在 **Set basic configurations** (設定基本組態) 頁面上，執行下列動作：
   + 在 **Target** (目標) 下，選擇您的目標裝置群組。
   + 在 **Security profile name** (安全性設定檔名稱) 下，輸入安全性設定檔的名稱。
   + (選用) 在 **Description** (描述) 下，您可以撰寫 ML 設定檔的簡短描述。
   + 在 **Selected metric behaviors in Security Profile** (安全性設定檔中選取的指標行為) 下，選擇您要監控的指標。  
![\[建立 ML 安全性設定檔組態頁面，當中包含選取作為目標的所有已註冊物件、列出的指標行為 (例如，授權失敗和連線嘗試次數)，以及新增雲端或裝置端指標的選項。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-set-basic.png)

   完成後，請選擇 **Next (下一步)**。

1. 在 **Set SNS (optional)** (設定 SNS (選用)) 頁面上，指定當裝置違反您設定檔中的行為時，警示通知的 SNS 主題。選擇您要用來發佈至所選 SNS 主題的 IAM 角色。

   如果您尚未有 SNS 角色，請使用下列步驟來建立具備適當許可和必要信任關係的角色。
   + 導覽至 [IAM 主控台](https://console.aws.amazon.com/iam/)。在導覽窗格中，選擇 **Roles** (角色)，然後選擇 **Create role** (建立角色)。
   + 在 **Select type of trusted entity** (選取信任的實體類型) 下，選取 **AWS 服務**。然後，在 **Choose a use case** (選擇使用案例) 下，選擇 **IoT**，並在 **Select your use case** (選取您的使用案例) 下，選擇 **IoT - Device Defender Mitigation Actions** (IoT - Device Defender 緩解動作)。完成時，請選擇 **Next: Permissions** (下一步：許可)。
   + 在 **Attached permissions policies** (連接的許可政策) 下，確保已選取 **AWSIoTDeviceDefenderPublishFindingsToSNSMitigationAction**，然後選擇 **Next: Tags** (下一步：標籤)。  
![\[AWS IoT Device Defender 角色的許可政策表，當中包含政策名稱、每一項政策所提供存取權的用途說明，以及篩選或搜尋政策的選項。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-sns-findings.png)
   + 在 **Add tags (optional)** (新增標籤 (選用)) 下，您可以新增想要與您角色建立關聯的任何標籤。完成後，請選擇 **Next: Review (下一步：檢閱)**。
   + 在 **Review** (檢閱) 下，給與您的角色一個名稱，並確保 **AWSIoTDeviceDefenderPublishFindingsToSNSMitigationAction** 已列示在 **Permissions** (許可) 下，而且 **** (AWS 服務：iot.amazonaws.com) 已列示在 **Trust relationships** (信任關係) 下。完成時，選擇 **Create role** (建立角色)。  
![\[IAM 角色摘要頁面，當中顯示 Sample-SNS-role 詳細資訊，例如角色 ARN、說明、執行個體設定檔 ARN、路徑、建立時間、工作階段持續時間上限，以及對 SNS 緩解動作政策套用的 AWS IoT Device Defender 發佈問題清單\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-detect-permissions.png)  
![\[IAM Sample-SNS-role 摘要，當中顯示角色 ARN、提供發佈 SNS 通知的 AWS IoT Device Defender 寫入存取權的角色說明、路徑、建立時間，以及受信任實體\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-detect-trust-relationships.png)

1. 在 **Edit Metric behavior** (編輯指標行為) 頁面上，您可以自訂 ML 行為設定。  
![\[編輯指標行為區段，其中包含授權失敗、輸入位元組數和連線嘗試次數指標，可讓您設定警示觸發、通知和 ML Detect 可信度等級的資料點。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-update-config.png)

1. 完成後，請選擇 **Next (下一步)**。

1. 在 **Review configuration** (檢閱組態) 頁面上，驗證您想要機器學習監控的行為，然後選擇 **Next** (下一步)。  
![\[編輯 ML 安全性設定檔頁面，當中顯示以所有已註冊物件為目標的 Smart_lights_ML_Detect_Security_Profile，包含授權失敗、輸出位元組數、連線嘗試次數和中斷連線次數的指標行為。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-review-config.png)

   

1. 在您建立了安全性設定檔之後，系統會將您重新導向至 **Security Profiles** (安全性設定檔) 頁面，其中會出現新建立的安全性設定檔。
**注意**  
初始的 ML 模型訓練和建置需要 14 天才能完成。如果您的裝置上有任何異常活動，您可能會在完成之後看到警示。

### 監控您的 ML 模型狀態
<a name="monitor-ml-models-console"></a>

當您的 ML 模型處於初始訓練期間時，您可以採取以下步驟隨時監控其進度。

1. 在 [AWS IoT 主控台](https://console.aws.amazon.com/iot)的導覽窗格中，展開 **Defend** (防禦)，然後選擇 **Detect** (偵測)、**Security profiles** (安全性描述檔)。

1. 在**Security Profiles** (安全性設定檔) 頁面上，選擇您要檢閱的安全性設定檔。然後，選擇 **Behaviors and ML training** (行為與 ML 訓練)。

1. 在 **Behaviors and ML training** (行為與 ML 訓練) 頁面上，檢查 ML 模型的訓練進度。

   在您的模型狀態為 **Active** (作用中) 之後，它會根據您的使用情況開始做出偵測決策，並每天更新設定檔。  
![\[此儀表板顯示低可信度的機器學習模型，用於監控 TCP/UDP 接聽程式連接埠和已建立的 TCP 連線。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-active-state.png)

**注意**  
如果您的模型未如預期進展，請確定您的裝置符合 [最低需求](dd-detect-ml.md#dd-detect-ml-requirements)。

### 檢閱您的 ML Detect 警示
<a name="review-ml-alarms-console"></a>

在建置您的 ML 模型並準備好進行資料推論之後，您可以定期檢視和調查模型識別的警示。

1. 在 [AWS IoT 主控台](https://console.aws.amazon.com/iot)的導覽窗格中，展開 **Defend** (防禦)，然後選擇 **Detect** (偵測)、**Alarms** (警示)。  
![\[AWS IoT Device Defender 警示清單，當中顯示 5 個作用中授權失敗警示，包含物件名稱、安全性設定檔、行為類型、行為名稱、上次發出時間及驗證狀態欄。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-alarms.png)

1. 如果導覽至 **History** (歷史記錄) 標籤，您也可以檢視不再處於警示狀態之裝置的詳細資訊。  
![\[此線形圖顯示兩週期間內的警示、已清除和已失效警示，y 軸表示警示數量，x 軸表示日期。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-history-alarm.png)

   若要取得詳細資訊，請在 **Manage** (管理) 下選擇 **Things** (物件)、選擇您想要查看其更多詳細資訊的物件，然後導覽至 **Defender metrics** (Defender 指標)。您可以存取 **Defender metrics graph** (Defender 指標圖形)，並針對警示中來自 **Active** (作用中) 標籤的任何項目執行調查。在此情況下，此圖形會顯示訊息大小中的峰值，這會啟動警示。您可以看到後續清除的警示。  
![\[IoT 物件儀表板會顯示所指定日期和時間的訊息大小最大指標圖，峰值為 801 個位元組。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-defender-metrics.png)

### 微調您的 ML 警示
<a name="fine-tune-ml-models-console"></a>

在建置您的 ML 模型並準備好進行資料評估之後，您可以更新安全性設定檔的 ML 行為設定以變更組態。下列程序顯示如何在 AWS CLI 中更新您安全性設定檔的 ML 行為設定。

1. 在 [AWS IoT 主控台](https://console.aws.amazon.com/iot)的導覽窗格中，展開 **Defend** (防禦)，然後選擇 **Detect** (偵測)、**Security profiles** (安全性描述檔)。

1. 在**Security Profiles** (安全性設定檔) 頁面上，選取您要檢閱之安全性設定檔旁邊的核取方塊。然後，選擇 **Actions** (動作)、**Edit** (編輯)。  
![\[AWS IoT Device Defender 安全性設定檔清單，當中顯示設定檔名稱、ML 閾值類型、保留的行為、目標物件、建立日期、通知狀態\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-fine-tune.png)

1. 在 **Set basic configurations** (設定基本組態) 下，您可以調整安全性設定檔目標物件群組，或變更您要監控的指標。  
![\[建立 ML 安全性設定檔組態頁面，當中包含選取作為目標的所有已註冊物件、列出的指標行為 (例如，授權失敗和連線嘗試次數)，以及新增雲端或裝置端指標的選項\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-set-basic.png)

1. 您可以導覽至 **Edit metric behaviors** (編輯指標行為) 來更新下列任一項。
   + 啟動警示所需的 ML 模型資料點
   + 清除警示所需的 ML 模型資料點
   + 您的 ML Detect 可信度
   + 您的 ML Detect 通知 (例如**Not suppressed** (未抑制)、**Suppressed** (已抑制))  
![\[編輯指標行為區段，當中包含設定 ML 安全性設定檔的授權失敗、輸出位元組數和連線嘗試次數指標的選項。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-update-config-2.png)

### 標記警示的驗證狀態
<a name="mark-your-alarms"></a>

設定驗證狀態並提供該驗證狀態的描述，以標記您的警示。這可協助您和團隊識別您不需要回應的警示。

1. 在 [AWS IoT 主控台](https://console.aws.amazon.com/iot/)的導覽窗格中，展開 **Defend** (防禦)，然後選擇 **Detect** (偵測)、**Alarms** (警示)。選取警示以標記其驗證狀態。  
![\[此 AWS IoT Device Defender 警示檢視會顯示 IoT 主控台物件的作用中授權失敗行為事件，例如 fdsa 安全性設定檔的 iotconsole-6f8379bc-c245-4ffe-8ef7-b2b52e78975c。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-alarm-select.png)

1. 選擇 **Mark verification state** (標記驗證狀態)。驗證狀態模式會開啟。

1. 選擇適當的驗證狀態、輸入驗證描述 (選填)，然後選擇 **Mark** (標記)。此動作會將驗證狀態和描述指派給所選警示。  
![\[用於標示警示驗證狀態的對話方塊，選項包括：不明、真陽性、誤報、良性肯定。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-alarm-state-window.png)

### 緩解已識別的裝置問題
<a name="mitigate-ml-issues-console"></a>

1. *(選用)* 在設定隔離緩解動作之前，讓我們先設定隔離群組，將違規裝置移至其中。您也可以使用現有群組

1. 導覽至 **Manage** (管理)、**Thing groups** (物件群組)，然後導覽至 **Create Thing Group** (建立物件群組)。命名您的物件群組 在本教學課程中，我們會將物件群組命名為 `Quarantine_group`。在 **Thing group** (物件群組)、**Security** (安全性) 下，將以下政策套用到物件群組。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Deny",
               "Action": "iot:*",
               "Resource": "*"
           }
       ]
   }
   ```

------  
![\[AWS IoT 控制台「建立物件群組」頁面，內含「建立物件群組」按鈕。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-create-thing-group.png)

   完成時，選擇 **Create thing group** (建立物件群組)。

1. 既然已建立物件群組，就讓我們建立一個緩解動作，將警示中的裝置移至 `Quarantine_group`。

   在 **Defend** (防禦)、**Mitigation actions** (緩解動作) 下，選擇 **Create** (建立)。  
![\[AWS IoT Device Defender 緩解動作組態表單，當中包含動作名稱、動作類型、許可、動作執行角色及物件群組欄位。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-miti-create.png)

1. 在 **Create a new mitigation action** (建立新的緩解動作) 頁面上，輸入下列資訊。
   + **Action name** (動作名稱)：為您的緩解動作命名，例如 **Quarantine\$1action**。
   + **Action type** (動作類型)：選擇動作的類型。我們將選擇 **Add things to thing group (Audit or Detect mitigation)** (將物件新增至物件群組 (稽核或偵測緩解))。
   + **Action execution role** (動作執行角色)：建立角色或選擇現有角色 (如果您先前已建立角色的話)。
   + **Parameters** (參數)：選擇物件群組。我們可以使用 `Quarantine_group`，這是我們先前建立的。  
![\[AWS IoT Device Defender 緩解動作組態表單，當中包含動作名稱、動作類型、許可、動作執行角色及物件群組欄位。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-miti-create-form.png)

   完成後，選擇**儲存**。您現在具可將警示中裝置移至隔離物件群組的緩解動作，以及可在調查時隔離裝置的緩解動作。

1. 導覽至 **Defender**、**Detect** (偵測)、**Alarms** (警示)。您可以在 **Active** (作用中) 下查看哪些裝置處於警示狀態，。  
![\[AWS IoT Device Defender 警示清單，當中顯示 5 個作用中授權失敗警示，包含物件名稱、安全性設定檔、行為類型、行為名稱、上次發出時間及驗證狀態欄。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-alarms.png)

   選取您要移至隔離群組的裝置，然後選擇 **Start Mitigation Actions** (啟動緩解動作)。

1. 在 **Start mitigation actions** (啟動緩解動作)、**Start Actions** (啟動動作) 下，選取您稍早建立的緩解動作。例如，我們將選擇 **Quarantine\$1action**，然後選擇 **Start** (啟動)。隨即開啟 Action Tasks (動作任務) 頁面。  
![\[緩解動作對話方塊，當中列出受影響的物件「udml7」，且包含用於確認不可復原動作的核取方塊，以及選擇要執行之動作的下拉式清單。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-start-action.png)

1. 現在，裝置在 **Quarantine\$1group** 中隔離，而且您可以調查引發警示的問題根本原因。完成調查後，您可以將裝置移出物件群組或採取進一步的動作。  
![\[AWS IoT Device Defender 偵測動作任務表，當中顯示一項會將物件新增至 quarantine_group 物件群組的隔離動作。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-ml-action-tasks.png)

   

## 如何搭配 CLI 使用 ML Detect
<a name="dd-detect-ml-cli"></a>

下列顯示如何使用 CLI 設定 ML Detect。

**Topics**
+ [

### 啟用 ML Detect
](#enable-ml-detect-cli)
+ [

### 監控您的 ML 模型狀態
](#monitor-ml-models-cli)
+ [

### 檢閱您的 ML Detect 警示
](#review-ml-alarms-cli)
+ [

### 微調您的 ML 警示
](#fine-tune-ml-models-cli)
+ [

### 標記警示的驗證狀態
](#mark-verification-state-cli)
+ [

### 緩解已識別的裝置問題
](#mitigate-issues-cli)

### 啟用 ML Detect
<a name="enable-ml-detect-cli"></a>

下列程序顯示如何在 AWS CLI 啟用 ML Detect。

1. 確保您的裝置將建立 [ML Detect 最低需求](dd-detect-ml.md#dd-detect-ml-requirements)中定義的最小必要資料點，以持續訓練和重新整理模型。如需進行資料收集，請確定您的物件位於已連接到安全性設定檔的物件群組中。

1. 使用 `[create-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/create-security-profile.html)` 命令建立 ML Detect 安全性設定檔。下列範例會建立名為 *security-profile-for-smart-lights* 的安全性設定檔，檢查傳送的訊息數目、授權失敗次數、連線嘗試次數，以及中斷連線次數。此範例會使用 `mlDetectionConfig`，以確定指標將使用 ML Detect 模型。

   ```
   aws iot create-security-profile \
       --security-profile-name security-profile-for-smart-lights \
       --behaviors \
        '[{
       "name": "num-messages-sent-ml-behavior",
       "metric": "aws:num-messages-sent",
       "criteria": {
         "consecutiveDatapointsToAlarm": 1,
         "consecutiveDatapointsToClear": 1,
         "mlDetectionConfig": {
           "confidenceLevel": "HIGH"
         }
       },
       "suppressAlerts": true
     },
     {
       "name": "num-authorization-failures-ml-behavior",
       "metric": "aws:num-authorization-failures",
       "criteria": {
         "consecutiveDatapointsToAlarm": 1,
         "consecutiveDatapointsToClear": 1,
         "mlDetectionConfig": {
           "confidenceLevel": "HIGH"
         }
       },
       "suppressAlerts": true
     },
     {
       "name": "num-connection-attempts-ml-behavior",
       "metric": "aws:num-connection-attempts",
       "criteria": {
         "consecutiveDatapointsToAlarm": 1,
         "consecutiveDatapointsToClear": 1,
         "mlDetectionConfig": {
           "confidenceLevel": "HIGH"
         }
       },
       "suppressAlerts": true
     },
     {
       "name": "num-disconnects-ml-behavior",
       "metric": "aws:num-disconnects",
       "criteria": {
         "consecutiveDatapointsToAlarm": 1,
         "consecutiveDatapointsToClear": 1,
         "mlDetectionConfig": {
           "confidenceLevel": "HIGH"
         }
       },
       "suppressAlerts": true
     }]'
   ```

   輸出：

   ```
   {
       "securityProfileName": "security-profile-for-smart-lights",
       "securityProfileArn": "arn:aws:iot:eu-west-1:123456789012:securityprofile/security-profile-for-smart-lights"
     }
   ```

1. 接下來，將您的安全性設定檔與一或多個物件群組建立關聯。使用 `[attach-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/attach-security-profile.html)` 命令，將物件群組連接至您的安全性設定檔。下列範例會將名為 *ML\$1Detect\$1beta\$1static\$1group* 的物件群組與 *security-profile-for-smart-lights* 安全性設定檔建立關聯。

   ```
   aws iot attach-security-profile \
   --security-profile-name security-profile-for-smart-lights \
   --security-profile-target-arn arn:aws:iot:eu-west-1:123456789012:thinggroup/ML_Detect_beta_static_group
   ```

   輸出：

   無。

1. 在您建立了完整的安全性設定檔之後，ML 模型就會開始訓練。初始的 ML 模型訓練和建置需要 14 天才能完成。14 天後，如果您的裝置上有任何異常活動，您可以預期看到警示。

### 監控您的 ML 模型狀態
<a name="monitor-ml-models-cli"></a>

下列程序顯示如何在進行中的訓練監控您的 ML 模型。
+ 使用 `[get-behavior-model-training-summaries](https://docs.aws.amazon.com/cli/latest/reference/iot/get-behavior-model-training-summaries.html)` 命令來檢視 ML 模型的進度。下列範例會取得 *security-profile-for-smart-lights* 安全性設定檔的 ML 模型訓練進度摘要。`modelStatus` 會顯示模型是否已完成訓練，或是由於特定行為仍在擱置建置。

  ```
  aws iot get-behavior-model-training-summaries \
     --security-profile-name security-profile-for-smart-lights
  ```

  輸出：

  ```
  {
      "summaries": [
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Messages_sent_ML_behavior",
              "trainingDataCollectionStartDate": "2020-11-30T14:00:00-08:00",
              "modelStatus": "ACTIVE",
              "datapointsCollectionPercentage": 29.408,
              "lastModelRefreshDate": "2020-12-07T14:35:19.237000-08:00"
          },
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Messages_received_ML_behavior",
              "modelStatus": "PENDING_BUILD",
              "datapointsCollectionPercentage": 0.0
          },
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Authorization_failures_ML_behavior",
              "trainingDataCollectionStartDate": "2020-11-30T14:00:00-08:00",
              "modelStatus": "ACTIVE",
              "datapointsCollectionPercentage": 35.464,
              "lastModelRefreshDate": "2020-12-07T14:29:44.396000-08:00"
          },
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Message_size_ML_behavior",
              "trainingDataCollectionStartDate": "2020-11-30T14:00:00-08:00",
              "modelStatus": "ACTIVE",
              "datapointsCollectionPercentage": 29.332,
              "lastModelRefreshDate": "2020-12-07T14:30:44.113000-08:00"
          },
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Connection_attempts_ML_behavior",
              "trainingDataCollectionStartDate": "2020-11-30T14:00:00-08:00",
              "modelStatus": "ACTIVE",
              "datapointsCollectionPercentage": 32.891999999999996,
              "lastModelRefreshDate": "2020-12-07T14:29:43.121000-08:00"
          },
          {
              "securityProfileName": "security-profile-for-smart-lights",
              "behaviorName": "Disconnects_ML_behavior",
              "trainingDataCollectionStartDate": "2020-11-30T14:00:00-08:00",
              "modelStatus": "ACTIVE",
              "datapointsCollectionPercentage": 35.46,
              "lastModelRefreshDate": "2020-12-07T14:29:55.556000-08:00"
          }
      ]
  }
  ```

**注意**  
如果您的模型未如預期進展，請確定您的裝置符合 [最低需求](dd-detect-ml.md#dd-detect-ml-requirements)。

### 檢閱您的 ML Detect 警示
<a name="review-ml-alarms-cli"></a>

在建置您的 ML 模型並準備好進行資料評估之後，您可以定期檢視模型所推論的任何警示。下列程序顯示如何在 AWS CLI 中檢視您的警示。
+ 若要查看所有作用中的警示，請使用 `[list-active-violations](https://docs.aws.amazon.com/cli/latest/reference/iot/list-active-violations.html)` 命令。

  ```
  aws iot list-active-violations \
  --max-results 2
  ```

  輸出：

  ```
  {
      "activeViolations": []
  }
  ```

  或者，您可以檢視在指定時段使用 `[list-violation-events](https://docs.aws.amazon.com/cli/latest/reference/iot/list-violation-events.html)` 命令探索到的所有違規。下列範例列出從 2020 年 9 月 22 日 5:42:13 GMT 到 2020 年 10 月 26 日 2020 5:42:13 GMT 的違規事件。

  ```
  aws iot list-violation-events \
      --start-time 1599500533 \ 
      --end-time 1600796533 \
      --max-results 2
  ```

  輸出：

  ```
  {
      "violationEvents": [
          {
              "violationId": "1448be98c09c3d4ab7cb9b6f3ece65d6",
              "thingName": "lightbulb-1",
              "securityProfileName": "security-profile-for-smart-lights",
              "behavior": {
                  "name": "LowConfidence_MladBehavior_MessagesSent",
                  "metric": "aws:num-messages-sent",
                  "criteria": {
                      "consecutiveDatapointsToAlarm": 1,
                      "consecutiveDatapointsToClear": 1,
                      "mlDetectionConfig": {
                          "confidenceLevel": "HIGH"
                      }
                  },
                  "suppressAlerts": true
              },
              "violationEventType": "alarm-invalidated",
              "violationEventTime": 1600780245.29
          },
          {
              "violationId": "df4537569ef23efb1c029a433ae84b52",
              "thingName": "lightbulb-2",
              "securityProfileName": "security-profile-for-smart-lights",
              "behavior": {
                  "name": "LowConfidence_MladBehavior_MessagesSent",
                  "metric": "aws:num-messages-sent",
                  "criteria": {
                      "consecutiveDatapointsToAlarm": 1,
                      "consecutiveDatapointsToClear": 1,
                      "mlDetectionConfig": {
                          "confidenceLevel": "HIGH"
                      }
                  },
                  "suppressAlerts": true
              },
              "violationEventType": "alarm-invalidated",
              "violationEventTime": 1600780245.281
          }
      ],
      "nextToken": "Amo6XIUrsOohsojuIG6TuwSR3X9iUvH2OCksBZg6bed2j21VSnD1uP1pflxKX1+a3cvBRSosIB0xFv40kM6RYBknZ/vxabMe/ZW31Ps/WiZHlr9Wg7R7eEGli59IJ/U0iBQ1McP/ht0E2XA2TTIvYeMmKQQPsRj/eoV9j7P/wveu7skNGepU/mvpV0O2Ap7hnV5U+Prx/9+iJA/341va+pQww7jpUeHmJN9Hw4MqW0ysw0Ry3w38hOQWEpz2xwFWAxAARxeIxCxt5c37RK/lRZBlhYqoB+w2PZ74730h8pICGY4gktJxkwHyyRabpSM/G/f5DFrD9O5v8idkTZzBxW2jrbzSUIdafPtsZHL/yAMKr3HAKtaABz2nTsOBNre7X2d/jIjjarhon0Dh9l+8I9Y5Ey+DIFBcqFTvhibKAafQt3gs6CUiqHdWiCenfJyb8whmDE2qxvdxGElGmRb+k6kuN5jrZxxw95gzfYDgRHv11iEn8h1qZLD0czkIFBpMppHj9cetHPvM+qffXGAzKi8tL6eQuCdMLXmVE3jbqcJcjk9ItnaYJi5zKDz9FVbrz9qZZPtZJFHp"
  }
  ```

### 微調您的 ML 警示
<a name="fine-tune-ml-models-cli"></a>

一旦建置了您的 ML 模型並準備好進行資料評估，您就可以更新安全性設定檔的 ML 行為設定以變更組態。下列程序顯示如何在 AWS CLI 中更新您安全性設定檔的 ML 行為設定。
+ 若要變更安全性設定檔的 ML 行為設定，請使用 `[update-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/update-security-profile.html)` 命令。下列範例會更新 *security-profile-for-smart-lights* 安全性設定檔的行為，方法為變更一些行為的 `confidenceLevel`，並取消抑制所有行為的通知。

  ```
  aws iot update-security-profile \
      --security-profile-name security-profile-for-smart-lights \
      --behaviors \
       '[{
        "name": "num-messages-sent-ml-behavior",
        "metric": "aws:num-messages-sent",
        "criteria": {
            "mlDetectionConfig": {
                "confidenceLevel" : "HIGH"
            }
        },
        "suppressAlerts": false
    },
    {
        "name": "num-authorization-failures-ml-behavior",
        "metric": "aws:num-authorization-failures",
        "criteria": {
            "mlDetectionConfig": {
                "confidenceLevel" : "HIGH"
            }
        },
        "suppressAlerts": false
    },
    {
        "name": "num-connection-attempts-ml-behavior",
        "metric": "aws:num-connection-attempts",
        "criteria": {
            "mlDetectionConfig": {
                "confidenceLevel" : "HIGH"
            }
        },
        "suppressAlerts": false
    },
    {
        "name": "num-disconnects-ml-behavior",
        "metric": "aws:num-disconnects",
        "criteria": {
            "mlDetectionConfig": {
                "confidenceLevel" : "LOW"
            }
        },
        "suppressAlerts": false
  
    }]'
  ```

  輸出：

  ```
   {
      "securityProfileName": "security-profile-for-smart-lights",
      "securityProfileArn": "arn:aws:iot:eu-west-1:123456789012:securityprofile/security-profile-for-smart-lights",
      "behaviors": [
          {
              "name": "num-messages-sent-ml-behavior",
              "metric": "aws:num-messages-sent",
              "criteria": {
                  "mlDetectionConfig": {
                      "confidenceLevel": "HIGH"
                  }
              }
          },
          {
              "name": "num-authorization-failures-ml-behavior",
              "metric": "aws:num-authorization-failures",
              "criteria": {
                  "mlDetectionConfig": {
                      "confidenceLevel": "HIGH"
                  }
              }
          },
          {
              "name": "num-connection-attempts-ml-behavior",
              "metric": "aws:num-connection-attempts",
              "criteria": {
                  "mlDetectionConfig": {
                      "confidenceLevel": "HIGH"
                  }
              },
              "suppressAlerts": false
          },
          {
              "name": "num-disconnects-ml-behavior",
              "metric": "aws:num-disconnects",
              "criteria": {
                  "mlDetectionConfig": {
                      "confidenceLevel": "LOW"
                  }
              },
              "suppressAlerts": true
          }
      ],
      "version": 2,
      "creationDate": 1600799559.249,
      "lastModifiedDate": 1600800516.856
  }
  ```

### 標記警示的驗證狀態
<a name="mark-verification-state-cli"></a>

您可以使用驗證狀態標記警示，以協助分類警示並調查異常情況。
+ 以驗證狀態和該狀態的描述標記警示。例如，若要將警示的驗證狀態設定為誤判，請使用下列命令：

  ```
  aws iot put-verification-state-on-violation --violation-id 12345  --verification-state FALSE_POSITIVE --verification-state-description "This is dummy description"  --endpoint https://us-east-1.iot.amazonaws.com --region us-east-1
  ```

  輸出：

  無。

### 緩解已識別的裝置問題
<a name="mitigate-issues-cli"></a>

1. 使用 `[create-thing-group](https://docs.aws.amazon.com/cli/latest/reference/iot/create-thing-group.html)` 命令，針對緩解動作建立物件群組。在下列範例中，我們會建立名為 **ThingGroupForDetectMitigationAction** 的物件群組。

   ```
   aws iot create-thing-group —thing-group-name ThingGroupForDetectMitigationAction
   ```

   輸出：

   ```
   {
    "thingGroupName": "ThingGroupForDetectMitigationAction",
    "thingGroupArn": "arn:aws:iot:us-east-1:123456789012:thinggroup/ThingGroupForDetectMitigationAction",
    "thingGroupId": "4139cd61-10fa-4c40-b867-0fc6209dca4d"
   }
   ```

1. 接下來，使用 `[create-mitigation-action](https://docs.aws.amazon.com/cli/latest/reference/iot/create-mitigation-action.html)` 命令來建立緩解動作。在下列範例中，我們會建立稱為 **detect\$1mitigation\$1action** 的緩解動作，搭配用來套用緩解動作之 IAM 角色的 ARN。我們也會定義動作的類型和該動作的參數。在此情況下，我們的緩解會將物件移到我們先前建立的物件群組，稱為 **ThingGroupForDetectMitigationAction**。

   ```
   aws iot create-mitigation-action --action-name detect_mitigation_action \
   --role-arn arn:aws:iam::123456789012:role/MitigationActionValidRole \
   --action-params \  
   '{
        "addThingsToThingGroupParams": {
            "thingGroupNames": ["ThingGroupForDetectMitigationAction"],
            "overrideDynamicGroups": false
        }
    }'
   ```

   輸出：

   ```
   {
    "actionArn": "arn:aws:iot:us-east-1:123456789012:mitigationaction/detect_mitigation_action",
    "actionId": "5939e3a0-bf4c-44bb-a547-1ab59ffe67c3"
   }
   ```

1. 使用 `[start-detect-mitigation-actions-task](https://docs.aws.amazon.com/cli/latest/reference/iot/start-detect-mitigation-actions-task.html)` 命令來啟動緩解動作任務。`task-id`、`target` 和 `actions` 是必要的參數。

   ```
   aws iot start-detect-mitigation-actions-task \
       --task-id taskIdForMitigationAction \
       --target '{ "violationIds" : [ "violationId-1", "violationId-2" ] }' \
       --actions "detect_mitigation_action" \
       --include-only-active-violations \
       --include-suppressed-alerts
   ```

   輸出：

   ```
   {
       "taskId": "taskIdForMitigationAction"
   }
   ```

1. (選用) 若要檢視任務中包含的緩解動作執行，請使用 `[list-detect-mitigation-actions-executions](https://docs.aws.amazon.com/cli/latest/reference/iot/list-detect-mitigation-actions-executions.html)` 命令。

   ```
   aws iot list-detect-mitigation-actions-executions \
       --task-id taskIdForMitigationAction \
       --max-items 5 \
       --page-size 4
   ```

   輸出：

   ```
   {
       "actionsExecutions": [
           {
               "taskId": "e56ee95e - f4e7 - 459 c - b60a - 2701784290 af",
               "violationId": "214_fe0d92d21ee8112a6cf1724049d80",
               "actionName": "underTest_MAThingGroup71232127",
               "thingName": "cancelDetectMitigationActionsTaskd143821b",
               "executionStartDate": "Thu Jan 07 18: 35: 21 UTC 2021",
               "executionEndDate": "Thu Jan 07 18: 35: 21 UTC 2021",
               "status": "SUCCESSFUL",
           }
       ]
   }
   ```

1. (選用) 使用 `[describe-detect-mitigation-actions-task](https://docs.aws.amazon.com/cli/latest/reference/iot/describe-detect-mitigation-actions-task.html)` 命令來取得緩解動作任務的相關資訊。

   ```
   aws iot describe-detect-mitigation-actions-task \
       --task-id taskIdForMitigationAction
   ```

   輸出：

   ```
   {
       "taskSummary": {
           "taskId": "taskIdForMitigationAction",
           "taskStatus": "SUCCESSFUL",
           "taskStartTime": 1609988361.224,
           "taskEndTime": 1609988362.281,
           "target": {
               "securityProfileName": "security-profile-for-smart-lights",
               "behaviorName": "num-messages-sent-ml-behavior"
           },
           "violationEventOccurrenceRange": {
               "startTime": 1609986633.0,
               "endTime": 1609987833.0
           },
           "onlyActiveViolationsIncluded": true,
           "suppressedAlertsIncluded": true,
           "actionsDefinition": [
               {
                   "name": "detect_mitigation_action",
                   "id": "5939e3a0-bf4c-44bb-a547-1ab59ffe67c3",
                   "roleArn": "arn:aws:iam::123456789012:role/MitigatioActionValidRole",
                   "actionParams": {
                       "addThingsToThingGroupParams": {
                           "thingGroupNames": [
                               "ThingGroupForDetectMitigationAction"
                           ],
                           "overrideDynamicGroups": false
                       }
                   }
               }
           ],
           "taskStatistics": {
               "actionsExecuted": 0,
               "actionsSkipped": 0,
               "actionsFailed": 0
           }
       }
   }
   ```

1. (選用) 若要取得緩解動作任務的清單，請使用 `[list-detect-mitigation-actions-tasks](https://docs.aws.amazon.com/cli/latest/reference/iot/list-detect-mitigation-actions-tasks.html)` 命令。

   ```
   aws iot list-detect-mitigation-actions-tasks \
       --start-time 1609985315 \
       --end-time 1609988915 \
       --max-items 5 \
       --page-size 4
   ```

   輸出：

   ```
   {
       "tasks": [
           {
               "taskId": "taskIdForMitigationAction",
               "taskStatus": "SUCCESSFUL",
               "taskStartTime": 1609988361.224,
               "taskEndTime": 1609988362.281,
               "target": {
                   "securityProfileName": "security-profile-for-smart-lights",
                   "behaviorName": "num-messages-sent-ml-behavior"
               },
               "violationEventOccurrenceRange": {
                   "startTime": 1609986633.0,
                   "endTime": 1609987833.0
               },
               "onlyActiveViolationsIncluded": true,
               "suppressedAlertsIncluded": true,
               "actionsDefinition": [
                   {
                       "name": "detect_mitigation_action",
                       "id": "5939e3a0-bf4c-44bb-a547-1ab59ffe67c3",
                       "roleArn": "arn:aws:iam::123456789012:role/MitigatioActionValidRole",
                       "actionParams": {
                           "addThingsToThingGroupParams": {
                               "thingGroupNames": [
                                   "ThingGroupForDetectMitigationAction"
                               ],
                               "overrideDynamicGroups": false
                           }
                       }
                   }
               ],
               "taskStatistics": {
                   "actionsExecuted": 0,
                   "actionsSkipped": 0,
                   "actionsFailed": 0
               }
           }
       ]
   }
   ```

1. (選用) 若要取消緩解動作任務，請使用 `[cancel-detect-mitigation-actions-task](https://docs.aws.amazon.com/cli/latest/reference/iot/cancel-detect-mitigation-actions-task.html)` 命令。

   ```
   aws iot cancel-detect-mitigation-actions-task \
       --task-id taskIdForMitigationAction
   ```

   輸出：

   無。

# 自訂您檢視 AWS IoT Device Defender 稽核結果的時間和方式
<a name="dd-suppressions-example"></a>

AWS IoT Device Defender 稽核會提供定期安全檢查，以確認 AWS IoT 裝置和資源都遵循最佳實務。對於每次檢查，稽核結果會分類為合規或不合規，其中不合規會產生主控台警告圖示。為了減少重複已知問題所產生的噪音，稽核發現結果抑制功能可讓您暫時讓這些不合規通知靜音。

您可以在預先決定的時段抑制特定資源或帳戶的選取稽核檢查。已抑制的稽核檢查結果會分類為抑制的發現結果，與合規和不合規的類別分開。這個新類別不會觸發警示，例如不合規的結果。這可讓您在已知維護期間或在排定的更新完成之前減少不合規的通知干擾。

## 開始使用
<a name="dd-gs-afs"></a>

下列各節詳述如何使用稽核發現結果抑制來抑制主控台和 CLI 中的 `Device certificate expiring` 檢查。如果想要遵循其中一個示範，您必須先建立兩個即將到期的憑證，以供 Device Defender 偵測。

使用下列動作來建立您的憑證。
+ 在《*AWS IoT Core開發人員指南*》中[建立和註冊 CA 憑證](https://docs.aws.amazon.com/iot/latest/developerguide/create-device-cert.html)
+ [使用您的憑證授權機構憑證建立用戶端憑證](https://docs.aws.amazon.com/iot/latest/developerguide/create-device-cert.html) 在步驟 3 中，將您的 `days` 參數設定為 **1**。

如果您是使用 CLI 建立憑證，請輸入以下命令。

```
openssl x509 -req \ 
    -in device_cert_csr_filename \ 
    -CA root_ca_pem_filename \ 
    -CAkey root_ca_key_filename \     
    -CAcreateserial \
    -out device_cert_pem_filename \ 
    -days 1 -sha256
```

## 在主控台中自訂您的稽核發現結果
<a name="dd-afs-example-console"></a>

下列演練會使用具有兩個過期裝置憑證的帳戶，這些憑證可觸發不合規的稽核檢查。在此案例中，我們想要停用警告，因為我們的開發人員正在測試將解決問題的新功能。我們會為每個憑證建立稽核發現結果抑制，以阻止稽核結果下週變成不合規。

1. 我們首先會執行隨需稽核，以顯示過期裝置憑證檢查不合規。

   從 [AWS IoT 主控台](https://console.aws.amazon.com/iot)的左側邊欄中，選擇 **Defend** (防禦)，然後依序選擇 **Audit** (稽核)、**Results** (結果)。在 **Audit Results** (稽核結果) 頁面上，選擇 **Create** (建立)。**Create a new audit** (建立新稽核) 視窗即會開啟。選擇 **Create** (建立)。  
![\[執行隨需稽核，以顯示過期裝置憑證檢查不合規。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-afs-noncompliant.png)

   從隨需稽核結果中，我們可以看到兩個資源的「裝置憑證即將到期」不合規。

1. 現在，我們想要停用「裝置憑證即將到期」不合規檢查警告，因為我們的開發人員正在測試將修正警告的新功能。

   從 **Defend** (防禦) 下的左側邊欄中，選擇 **Audit** (稽核)，然後選擇 **Finding suppressions** (發現結果抑制)。在 **Audit finding suppressions** (稽核發現結果抑制) 頁面上，選擇 **Create** (建立)。  
![\[在主控台中建立稽核問題清單抑制的流程。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-afs-suppressions.png)

1. 在 **Create an audit finding suppression** (建立稽核發現結果抑制) 視窗上，我們需要填寫以下內容。
   + **Audit check** (稽核檢查)：我們選取 `Device certificate expiring`，因為這是我們想要抑制的稽核檢查。
   + **Resource identifier** (資源識別符)：我們輸入其中一個想要抑制其稽核發現結果之憑證的裝置憑證 ID。
   + **Suppression duration** (抑制持續時間)：我們選取 `1 week`，因為這是我們想要抑制 `Device certificate expiring` 稽核檢查的時間長度
   + **Description (optional)** (描述 (選用))：我們新增附註，描述為什麼我們要抑制此稽核發現結果。  
![\[您需要在此輸入詳細資訊的「建立稽核問題清單抑制」頁面。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-afs-create.png)

   在填寫完這些欄位之後，請選擇 **Create** (建立)。在建立了稽核發現結果抑制之後，我們會看到成功橫幅。

1. 我們已抑制其中一個憑證的稽核發現結果，現在我們需要抑制第二個憑證的稽核發現結果。我們可以使用在步驟 3 中使用的同一抑制方法，但我們將使用不同的方法進行示範。

   從 **Defend** (防禦) 下的左側邊欄中，選擇 **Audit** (稽核)，然後選擇 **Results** (結果)。在 **Audit results** (稽核結果) 頁面上，選擇具有不合規資源的稽核。然後，在 **Non-compliant checks** (不合規檢查) 下選取資源。在我們的案例中，我們選取「裝置憑證即將到期」。

1. 在 **Device certificate expiring** (裝置憑證即將到期) 頁面上，於 **Non-compliant policy** (不合規政策) 下選擇需要抑制之發現結果旁邊的選項按鈕。接著，選擇 **Actions** (動作) 下拉式選單，然後選擇您想要抑制發現結果的持續時間。在我們的案例中，我們選擇 `1 week`，就像我們為其他憑證所做的一樣。在 **Confirm suppression** (確認抑制) 視窗上，選擇 **Enable suppression** (啟用抑制)。  
![\[您完成此流程的「建立稽核抑制」頁面。稽核問題清單抑制建立完成後，您將會看到成功橫幅。\]](http://docs.aws.amazon.com/zh_tw/iot-device-defender/latest/devguide/images/dd-afs-noncompliantcerts.png)

   在建立了稽核發現結果抑制之後，我們會看到成功橫幅。現在，這兩個稽核發現結果已被抑制 1 週，而我們的開發人員正在研究解決這個警告的解決方案。

## 在 CLI 中自訂您的稽核發現結果
<a name="dd-afs-example-cli"></a>

下列演練會使用具有過期裝置憑證的帳戶，此憑證可觸發不合規的稽核檢查。在此案例中，我們想要停用警告，因為我們的開發人員正在測試將解決問題的新功能。我們會為憑證建立稽核發現結果抑制，以阻止稽核結果下週變成不合規。

我們使用以下 CLI 命令。
+ [create-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/create-audit-suppression.html)
+ [describe-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/describe-audit-suppression.html)
+ [update-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/update-audit-suppression.html)
+ [delete-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/delete-audit-suppression.html)
+ [list-audit-suppressions](https://docs.aws.amazon.com/cli/latest/reference/iot/list-audit-suppressions.html)

1. 請使用下列命令來啟用稽核。

   ```
   aws iot update-account-audit-configuration \
      --audit-check-configurations "{\"DEVICE_CERTIFICATE_EXPIRING_CHECK\":{\"enabled\":true}}"
   ```

   輸出：

   無。

1. 使用下列命令來執行將 `DEVICE_CERTIFICATE_EXPIRING_CHECK` 稽核檢查設為目標的隨需稽核。

   ```
   aws iot start-on-demand-audit-task \
       --target-check-names DEVICE_CERTIFICATE_EXPIRING_CHECK
   ```

   輸出：

   ```
   {
       "taskId": "787ed873b69cb4d6cdbae6ddd06996c5"
   }
   ```

1. 使用 [describe-account-audit-configuration](https://docs.aws.amazon.com/cli/latest/reference/iot/describe-account-audit-configuration.html) 命令來描述稽核組態。我們想要確認已開啟 `DEVICE_CERTIFICATE_EXPIRING_CHECK` 的稽核檢查。

   ```
   aws iot describe-account-audit-configuration
   ```

   輸出：

   ```
   {
       "roleArn": "arn:aws:iam::<accountid>:role/service-role/project",
       "auditNotificationTargetConfigurations": {
           "SNS": {
               "targetArn": "arn:aws:sns:us-east-1:<accountid>:project_sns",
               "roleArn": "arn:aws:iam::<accountid>:role/service-role/project",
               "enabled": true
           }
       },
       "auditCheckConfigurations": {
           "AUTHENTICATED_COGNITO_ROLE_OVERLY_PERMISSIVE_CHECK": {
               "enabled": false
           },
           "CA_CERTIFICATE_EXPIRING_CHECK": {
               "enabled": false
           },
           "CA_CERTIFICATE_KEY_QUALITY_CHECK": {
               "enabled": false
           },
           "CONFLICTING_CLIENT_IDS_CHECK": {
               "enabled": false
           },
           "DEVICE_CERTIFICATE_EXPIRING_CHECK": {
               "enabled": true
           },
           "DEVICE_CERTIFICATE_KEY_QUALITY_CHECK": {
               "enabled": false
           },
           "DEVICE_CERTIFICATE_SHARED_CHECK": {
               "enabled": false
           },
           "IOT_POLICY_OVERLY_PERMISSIVE_CHECK": {
               "enabled": true
           },
           "IOT_ROLE_ALIAS_ALLOWS_ACCESS_TO_UNUSED_SERVICES_CHECK": {
               "enabled": false
           },
           "IOT_ROLE_ALIAS_OVERLY_PERMISSIVE_CHECK": {
               "enabled": false
           },
           "LOGGING_DISABLED_CHECK": {
               "enabled": false
           },
           "REVOKED_CA_CERTIFICATE_STILL_ACTIVE_CHECK": {
               "enabled": false
           },
           "REVOKED_DEVICE_CERTIFICATE_STILL_ACTIVE_CHECK": {
               "enabled": false
           },
           "UNAUTHENTICATED_COGNITO_ROLE_OVERLY_PERMISSIVE_CHECK": {
               "enabled": false
           }
       }
   }
   ```

   `DEVICE_CERTIFICATE_EXPIRING_CHECK` 應該具有 `true` 一值。

1. 使用 [list-audit-task](https://docs.aws.amazon.com/cli/latest/reference/iot/list-audit-task.html) 命令來識別已完成的稽核任務。

   ```
   aws iot list-audit-tasks \
       --task-status "COMPLETED" \
       --start-time 2020-07-31 \
       --end-time 2020-08-01
   ```

   輸出：

   ```
   {
       "tasks": [
           {
               "taskId": "787ed873b69cb4d6cdbae6ddd06996c5",
               "taskStatus": "COMPLETED",
               "taskType": "SCHEDULED_AUDIT_TASK"
           }
       ]
   }
   ```

   您在步驟 1 中執行的 `taskId` 稽核，其具有的 `taskStatus` 應為 `COMPLETED`。

1. 使用 [describe-audit-task](https://docs.aws.amazon.com/cli/latest/reference/iot/describe-audit-task.html) 命令，透過來自前一個步驟的 `taskId` 輸出，來取得已完成稽核的詳細資訊。此命令會列出稽核的詳細資訊。

   ```
   aws iot describe-audit-task \
       --task-id "787ed873b69cb4d6cdbae6ddd06996c5"
   ```

   輸出：

   ```
   {
       "taskStatus": "COMPLETED",
       "taskType": "SCHEDULED_AUDIT_TASK",
       "taskStartTime": 1596168096.157,
       "taskStatistics": {
           "totalChecks": 1,
           "inProgressChecks": 0,
           "waitingForDataCollectionChecks": 0,
           "compliantChecks": 0,
           "nonCompliantChecks": 1,
           "failedChecks": 0,
           "canceledChecks": 0
       },
       "scheduledAuditName": "AWSIoTDeviceDefenderDailyAudit",
       "auditDetails": {
           "DEVICE_CERTIFICATE_EXPIRING_CHECK": {
               "checkRunStatus": "COMPLETED_NON_COMPLIANT",
               "checkCompliant": false,
               "totalResourcesCount": 195,
               "nonCompliantResourcesCount": 2
           }
       }
   }
   ```

1. 使用 [list-audit-findings](https://docs.aws.amazon.com/cli/latest/reference/iot/list-audit-findings.html) 命令來尋找不合規的憑證 ID，以便我們可以暫停此資源的稽核警示。

   ```
   aws iot list-audit-findings \
       --start-time 2020-07-31 \
       --end-time 2020-08-01
   ```

   輸出：

   ```
   {
       "findings": [
           {
               "findingId": "296ccd39f806bf9d8f8de20d0ceb33a1",
               "taskId": "787ed873b69cb4d6cdbae6ddd06996c5",
               "checkName": "DEVICE_CERTIFICATE_EXPIRING_CHECK",
               "taskStartTime": 1596168096.157,
               "findingTime": 1596168096.651,
               "severity": "MEDIUM",
               "nonCompliantResource": {
                   "resourceType": "DEVICE_CERTIFICATE",
                   "resourceIdentifier": {
                       "deviceCertificateId": "b4490<shortened>"
                   },
                   "additionalInfo": {
                   "EXPIRATION_TIME": "1582862626000"
                   }
               },
               "reasonForNonCompliance": "Certificate is past its expiration.",
               "reasonForNonComplianceCode": "CERTIFICATE_PAST_EXPIRATION",
               "isSuppressed": false
           },
           {
               "findingId": "37ecb79b7afb53deb328ec78e647631c",
               "taskId": "787ed873b69cb4d6cdbae6ddd06996c5",
               "checkName": "DEVICE_CERTIFICATE_EXPIRING_CHECK",
               "taskStartTime": 1596168096.157,
               "findingTime": 1596168096.651,
               "severity": "MEDIUM",
               "nonCompliantResource": {
                   "resourceType": "DEVICE_CERTIFICATE",
                   "resourceIdentifier": {
                       "deviceCertificateId": "c7691<shortened>"
                   },
                   "additionalInfo": {
                   "EXPIRATION_TIME": "1583424717000"
                   }
               },
               "reasonForNonCompliance": "Certificate is past its expiration.",
               "reasonForNonComplianceCode": "CERTIFICATE_PAST_EXPIRATION",
               "isSuppressed": false
           }
      ]
   }
   ```

1. 使用 [create-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/create-audit-suppression.html) 命令，來抑制裝置憑證 (ID 為 `c7691e<shortened>`) 之 `DEVICE_CERTIFICATE_EXPIRING_CHECK` 稽核檢查的通知，直到 *2020-08-20*。

   ```
   aws iot create-audit-suppression \
       --check-name DEVICE_CERTIFICATE_EXPIRING_CHECK \
       --resource-identifier deviceCertificateId="c7691e<shortened>" \
       --no-suppress-indefinitely \ 
       --expiration-date 2020-08-20
   ```

1. 使用 [list-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/list-audit-suppression.html) 命令，來確認稽核抑制設定，並取得有關抑制的詳細資訊。

   ```
   aws iot list-audit-suppressions
   ```

   輸出：

   ```
   {
       "suppressions": [
           {
           "checkName": "DEVICE_CERTIFICATE_EXPIRING_CHECK",
               "resourceIdentifier": {
                   "deviceCertificateId": "c7691e<shortened>"
               },
           "expirationDate": 1597881600.0,
           "suppressIndefinitely": false
           }
       ]
   }
   ```

1. [update-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/update-audit-suppression.html) 命令可以用來更新稽核發現結果抑制。下列範例會將 `expiration-date` 更新為 `08/21/20`。

   ```
   aws iot update-audit-suppression \
       --check-name DEVICE_CERTIFICATE_EXPIRING_CHECK \
       --resource-identifier deviceCertificateId=c7691e<shortened> \
       --no-suppress-indefinitely \
       --expiration-date 2020-08-21
   ```

1. [delete-audit-suppression](https://docs.aws.amazon.com/cli/latest/reference/iot/delete-audit-suppression.html) 命令可以用來移除稽核發現結果抑制。

   ```
   aws iot delete-audit-suppression \
       --check-name DEVICE_CERTIFICATE_EXPIRING_CHECK \
       --resource-identifier deviceCertificateId="c7691e<shortened>"
   ```

   若要確認刪除，請使用 [list-audit-suppressions](https://docs.aws.amazon.com/cli/latest/reference/iot/list-audit-suppressions.html) 命令。

   ```
   aws iot list-audit-suppressions
   ```

   輸出：

   ```
   {
    "suppressions": []
   }
   ```

在本教學課程中，我們已展示如何抑制主控台和 CLI 中的 `Device certificate expiring` 檢查。如需稽核發現結果抑制的詳細資訊，請參閱 [稽核發現結果抑制](audit-finding-suppressions.md)