

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

# 刪除通知規則目標
<a name="notification-target-delete"></a>

如果不再需要目標，可以將其刪除。一個資源只能設定 10 個通知規則目標，因此刪除不需要的目標有助於為可能要新增到該通知規則的其他目標騰出空間。

**注意**  
刪除通知規則目標會將目標從設定將其做為目標的所有通知規則中移除，但不會刪除目標本身。<a name="notification-target-delete-console"></a>

# 刪除通知規則目標 (主控台)
<a name="notification-target-delete-console"></a>

1. 開啟位於 https：//[https://console.aws.amazon.com/codesuite/settings/notifications](https://console.aws.amazon.com/codesuite/settings/notifications/) 的 AWS 開發人員工具主控台。

1. 在導覽列中，展開 **Settings (設定)**，然後選擇 **Notification rules (通知規則)**。

1. 在**通知規則目標**中，檢閱 AWS 區域 您目前登入之 AWS 帳戶中為資源設定的目標清單。使用選擇器變更 AWS 區域。

1. 選擇通知規則目標，然後選擇 **Delete (刪除)**。

1. 輸入 **delete**，然後選擇 **Delete (刪除)**。<a name="notification-target-delete-cli"></a>

# 刪除通知規則目標 (AWS CLI)
<a name="notification-target-delete-cli"></a>

1. 在終端機或命令提示字元中，執行 **delete-target** 命令，並指定目標的 ARN。例如，下列命令會刪除使用 Amazon SNS 主題的目標。

   ```
   aws codestar-notifications delete-target --target-address arn:aws:sns:{{us-east-1}}:{{123456789012}}:{{MyNotificationTopic}}
   ```

1. 如果成功，此命令不會傳回任何內容。如果失敗，此命令會傳回錯誤。最常見的錯誤是主題為一或多個通知規則的目標。

   ```
   An error occurred (ValidationException) when calling the DeleteTarget operation: Unsubscribe target before deleting.
   ```

   您可以使用 `--force-unsubscribe-all` 參數，將目標從設定以其為目標的所有通知規則中移除，然後刪除該目標。

   ```
   aws codestar-notifications delete-target --target-address arn:aws:sns:{{us-east-1}}:{{123456789012}}:{{MyNotificationTopic}} --force-unsubscribe-all
   ```