

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

# 新增或移除通知規則的目標
<a name="notification-target-change-rule"></a>

您可以編輯通知規則，以變更傳送通知的一或多個目標。您可以使用開發人員工具主控台或 或 AWS CLI 來變更通知規則的目標。<a name="notification-target-change-rule-console"></a>

# 變更通知規則的目標 (主控台)
<a name="notification-target-change-rule-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. 選擇規則，然後選擇 **Edit (編輯)**。

1. 在 **Targets (目標)** 中，執行下列其中一個動作：
   + 若要新增另一個目標，請選擇**新增目標**，然後從清單中選擇您要新增的 Amazon SNS 主題或 AWS Chatbot (Slack) 或 AWS Chatbot (Microsoft Teams) 用戶端。您也可以選擇 **Create SNS topic (建立 SNS 主題)** 來建立主題並新增為目標。一個通知規則最多可有 10 個目標。
   + 若要移除目標，請選擇您要移除的目標旁邊的 **Remove target (移除目標)**。

1. 選擇**提交**。<a name="notification-target-change-rule-add-cli"></a>

# 新增目標到通知規則 (AWS CLI)
<a name="notification-target-change-rule-add-cli"></a>

1. 在終端機或命令提示字元中，執行 **subscribe** 命令以新增目標。例如，以下命令會新增 Amazon SNS 主題做為通知規則的目標。

   ```
   aws codestar-notifications subscribe --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
   ```

1. 如果成功，此命令會傳回所更新通知規則的 ARN，如下所示。

   ```
   {
       "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
   }
   ```<a name="notification-target-change-rule-remove-cli"></a>

# 從通知規則移除目標 (AWS CLI)
<a name="notification-target-change-rule-remove-cli"></a>

1. 在終端機或命令提示字元中，執行 **unsubscribe** 命令以移除目標。例如，以下命令會移除做為通知規則目標的 Amazon SNS 主題。

   ```
   aws codestar-notifications unsubscribe --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
   ```

1. 如果成功，此命令會傳回所更新通知規則的 ARN 和所移除目標的相關資訊，如下所示。

   ```
   {
       "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE"
       "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic"
   }
   ```

## 另請參閱
<a name="notification-target-change-also"></a>
+ [編輯通知規則](notification-rule-edit.md)
+ [啟用或停用通知規則的通知](notification-rule-enable-disable.md)