

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

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

如果您有適用於 AWS CodeCommit AWS CodeDeploy IAM 使用者或角色的受管政策 AWS CodeBuild，或 AWS CodePipeline 已套用到 IAM 使用者或角色，則具有在政策提供的角色和許可限制內使用通知所需的許可。例如，已套用 `AWSCodeBuildAdminAccess`、`AWSCodeCommitFullAccess`、`AWSCodeDeployFullAccess` 或 `AWSCodePipeline_FullAccess` 受管政策的使用者，具有通知的完整管理存取權。

如需包含範例政策的詳細資訊，請參閱[身分型政策](security-iam.md#security_iam_access-manage-id-based-policies)。

如果您已將其中一個政策套用至 IAM 使用者或角色，以及 CodeBuild 中的建置專案、CodeCommit 中的儲存庫、CodeDeploy 中的部署應用程式或 CodePipeline 中的管道，便可以開始建立第一個通知規則。繼續進行[開始使用通知](getting-started.md)。否則請參閱下列主題：
+ CodeBuild：[開始使用 CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html)
+ CodeCommit：[開始使用 CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html)
+ CodeDeploy：[教學](https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials.html)
+ CodePipeline：[開始使用 CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-codepipeline.html)

 如果您要自行管理 IAM 使用者、群組或角色的通知管理許可，請遵循本主題中的程序，設定使用服務所需的許可和資源。

如果您想要使用先前為通知建立的 Amazon SNS 主題，而不特別為通知建立主題，則必須套用允許事件發佈至 Amazon SNS 主題的政策，以設定該主題作為通知規則的目標。

**注意**  
若要執行下列程序，您必須使用具有管理許可的帳戶登入。如需詳細資訊，請參閱[建立您的第一個 IAM 管理員使用者和群組](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html)。

**Topics**
+ [建立和套用通知的管理存取政策](#set-up-permissions)
+ [設定通知的 Amazon SNS 主題](set-up-sns.md)
+ [讓使用者訂閱做為目標的 Amazon SNS 主題](subscribe-users-sns.md)

## 建立和套用通知的管理存取政策
<a name="set-up-permissions"></a>

您可以使用 IAM 使用者登入，或使用具有存取 服務和您要為其建立通知之服務 (AWS CodeBuild AWS CodeCommit AWS CodeDeploy、 或 AWS CodePipeline) 許可的角色來管理通知。您也可以建立自己的政策，並套用至使用者或群組。

下列程序顯示如何設定具有許可管理通知和新增 IAM 使用者的 IAM 群組。如果您不想設定群組，可以直接將此政策套用到 IAM 使用者，或使用者可擔任的 IAM 角色。您也可以對 CodeBuild、CodeCommit、CodeDeploy 或 CodePipeline 使用受管政策，其中包含通知功能的策略適用存取權 (視政策的範圍而定)。

針對下方的政策，輸入名稱 (例如 `AWSCodeStarNotificationsFullAccess`) 和此政策的選用說明。說明可協助您記住政策的目的 (例如，**This policy provides full access to AWS CodeStar Notifications.**

**若要使用 JSON 政策編輯器來建立政策**

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

1. 在左側的導覽窗格中，選擇 **Policies (政策)**。

   如果這是您第一次選擇 **Policies (政策)**，將會顯示 **Welcome to Managed Policies (歡迎使用受管政策)** 頁面。選擇 **Get Started (開始使用)**。

1. 在頁面頂端，選擇 **Create policy (建立政策)**。

1. 在**政策編輯器**中，選擇 **JSON** 選項。

1. 輸入下列 JSON 政策文件：

   ```
    {
       "Version": "2012-10-17",		 	 	 
       "Statement": [
         {
           "Sid": "AWSCodeStarNotificationsFullAccess",
           "Effect": "Allow",
           "Action": [
               "codestar-notifications:CreateNotificationRule",
               "codestar-notifications:DeleteNotificationRule",
               "codestar-notifications:DescribeNotificationRule",
               "codestar-notifications:ListNotificationRules",
               "codestar-notifications:UpdateNotificationRule",
               "codestar-notifications:Subscribe",
               "codestar-notifications:Unsubscribe",
               "codestar-notifications:DeleteTarget",
               "codestar-notifications:ListTargets",
               "codestar-notifications:ListTagsforResource",
               "codestar-notifications:TagResource",
               "codestar-notifications:UntagResource"
           ],
           "Resource": "*"
        }
      ]
   }
   ```

1. 選擇**下一步**。
**注意**  
您可以隨時切換**視覺化**與 **JSON** 編輯器選項。不過，如果您進行變更或在**視覺化**編輯器中選擇**下一步**，IAM 就可能會調整您的政策結構，以便針對視覺化編輯器進行最佳化。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[調整政策結構](https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_policies.html#troubleshoot_viseditor-restructure)。

1. 在**檢視與建立**頁面上，為您正在建立的政策輸入**政策名稱**與**描述** (選用)。檢視**此政策中定義的許可**，來查看您的政策所授予的許可。

1. 選擇 **Create policy** (建立政策) 儲存您的新政策。