

# 如何使用 AWS IoT Device Defender Detect
<a name="detect-HowToHowTo"></a>

1. 您可以僅透過雲端指標來使用 AWS IoT Device Defender Detect，但如果打算使用裝置報告指標，則必須先在您的 AWS IoT 連網裝置或裝置閘道上部署 AWS IoT SDK。如需詳細資訊，請參閱[從裝置傳送指標](detect-device-side-metrics.md#DetectMetricsMessages)。

1. 請考慮在定義行為及建立警示之前，檢視您的裝置所產生的指標。AWS IoT 可以從您的裝置收集指標，以便您先針對一組裝置或您帳戶中的所有裝置識別正常或異常行為。使用 [CreateSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateSecurityProfile.html)，但只指定那些您感興趣的 `additionalMetricsToRetain`。此時不要指定 `behaviors`。

   使用 AWS IoT 主控台來查看您的裝置指標，以查看何者構成您裝置的典型行為。

1. 為您的安全性描述檔建立一組行為。包含指標的行為，其為您帳戶中的一組裝置或所有裝置指定正常行為。如需詳細資訊和範例，請參閱 [雲端指標](detect-cloud-side-metrics.md) 和 [裝置端指標](detect-device-side-metrics.md)。在建立一組行為之後，您可以使用 [ValidateSecurityProfileBehaviors](https://docs.aws.amazon.com/iot/latest/apireference/API_ValidateSecurityProfileBehaviors.html) 來驗證它們。

1. 使用 [CreateSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateSecurityProfile.html) 動作建立包含您行為的安全性設定檔。當裝置違反行為時，您可以使用 `alertTargets` 參數將警示傳送到目標 (SNS 主題)。(如果您使用 SNS 傳送警示，請注意，這些都會計入您 AWS 帳戶 帳戶的 SNS 主題配額。大量違規爆發可能會超過您的 SNS 主題配額。您也可以使用 CloudWatch 指標來檢查違規。如需詳細資訊，請參閱《*AWS IoT Core 開發人員指南*》中的[使用 Amazon CloudWatch 監控 AWS IoT 警示和指標](https://docs.aws.amazon.com/iot/latest/developerguide/monitoring-cloudwatch.html)。

1. 使用 [AttachSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_AttachSecurityProfile.html) 動作將安全性設定檔連接到裝置群組 (物件群組)、您帳戶中所有已註冊的物件，所有未註冊的物件，或所有裝置。AWS IoT Device Defender Detect 會開始檢查異常行為，若偵測到違規行為，便會傳送警示。如果您預期與不在您帳戶的物件登錄檔中的行動裝置互動，則可將安全性描述檔附加到所有未註冊的物件。您可以定義適用於不同裝置群組的不同行為，以符合您的需求。

   若要將安全性描述檔附加到一組裝置，您必須指定包含該裝置的物件群組的 ARN。此物件群組 ARN 的格式如下：

   ```
   arn:aws:iot:region:account-id:thinggroup/thing-group-name
   ```

   若要將安全性設定檔連接到 AWS 帳戶 中所有已註冊的物件 (忽略未註冊的物件)，您必須指定具下列格式的 ARN。

   ```
   arn:aws:iot:region:account-id:all/registered-things
   ```

   若要將安全性描述檔附加到所有未註冊的物件，您必須指定具下列格式的 ARN。

   ```
   arn:aws:iot:region:account-id:all/unregistered-things
   ```

   若要將安全性描述檔附加到所有裝置，您必須指定具下列格式的 ARN。

   ```
   arn:aws:iot:region:account-id:all/things
   ```

1. 您也可以使用 [ListActiveViolations](https://docs.aws.amazon.com/iot/latest/apireference/API_ListActiveViolations.html) 動作追蹤違規，這可讓您查看某特定安全性設定檔或目標裝置被偵測到的違規。

   使用 [ListViolationEvents](https://docs.aws.amazon.com/iot/latest/apireference/API_ListViolationEvents.html) 動作查看在指定期間內偵測到哪些違規。您可以透過安全性描述檔、裝置或警示驗證狀態來篩選這些結果。

1. 您可以透過標記警示的驗證狀態來驗證、組織和管理警示，並使用 [PutVerificationStateOnViolation](https://docs.aws.amazon.com/iot/latest/apireference/API_PutVerificationStateOnViolation.html) 動作來提供該驗證狀態的描述。

1. 如果您的裝置違反所定義行為的次數太過頻繁，或是不夠頻繁，您應該微調行為定義。

1. 若要檢閱您設定的安全性設定檔，以及受監控的裝置，請使用 [ListSecurityProfiles](https://docs.aws.amazon.com/iot/latest/apireference/API_ListSecurityProfiles.html)、[ListSecurityProfilesForTarget](https://docs.aws.amazon.com/iot/latest/apireference/API_ListSecurityProfilesForTarget.html) 和 [ListTargetsForSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_ListTargetsForSecurityProfile.html) 動作。

   使用 [DescribeSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeSecurityProfile.html) 動作取得更多有關安全性設定檔的詳細資訊。

1. 若要更新安全性設定檔，請使用 [UpdateSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_UpdateSecurityProfile.html) 動作。使用 [DetachSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_DetachSecurityProfile.html) 動作，將安全性設定檔從帳戶或目標物件群組中分開。請使用 [DeleteSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_DeleteSecurityProfile.html) 動作來完全刪除安全性設定檔。