連接和分離標籤政策 - AWS Organizations

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

連接和分離標籤政策

您可以在整個組織及組織單位 (OU) 和個別帳戶上使用標籤政策。

  • 當您將標籤政策連接至組織根時,此標籤政策會套用至該根的所有成員 OU 和帳戶。

  • 當您將標籤政策連接至 OU 時,該標籤政策會套用至屬於此 OU 的帳戶。這些帳戶也遵從連接至組織根的任何標籤政策。

  • 當您將標籤政策連接至帳戶時,該標籤政策會套用至此帳戶。此外,該帳戶受制於連接至組織根的任何標籤政策,還有連接至該帳戶所屬 OU 的任何標籤政策。

帳戶繼承的任何標籤政策,加上直接連接至帳戶的任何標籤政策,聚集而成有效的標籤政策。如需詳細資訊,請參閱 理解管理政策繼承

重要

未標記的資源由於不合規而無法出現在結果中。

最低許可

若要連接標籤政策,您必須具有執行下列動作的許可:

  • organizations:AttachPolicy

您可以導覽至政策或連接政策的根、OU 或帳戶,以連接標籤政策。

導覽至根、OU 或帳戶以連接標籤政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. AWS 帳戶 頁面上,導覽至您要連接政策的根、OU 或帳戶的名稱並選擇。您可能需要展開 OU (選擇 ),以尋找您所需的 OU 和帳戶。

  3. Policies (政策) 索引標籤的 Tag policies (標籤政策) 項目中,選擇 Attach (連接)。

  4. 尋找您所需的政策,然後選擇 Attach policy (連接政策)。

    Policies (政策) 索引標籤上的連接的標籤政策清單會更新,以包含新的新增項目。政策變更會立即生效。

導覽至政策以連接標籤政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. Tag policies (標籤政策) 頁面上,選擇您要連接的政策名稱。

  3. Targets (目標) 索引標籤上,選擇 Attach (連接)。

  4. 選擇您要連接政策的根、OU 或帳戶旁的選項按鈕。您可能需要展開 OU (選擇 ),以尋找您所需的 OU 和帳戶。

  5. 選擇連接政策

    Targets (目標) 索引標籤上的連接的標籤政策清單會更新,以包含新的新增項目。政策變更會立即生效。

將標籤原則附加至組織根目錄、OU 或帳號

下列程式碼範例會示範如何使用AttachPolicy

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Shows how to attach an AWS Organizations policy to an organization, /// an organizational unit, or an account. /// </summary> public class AttachPolicy { /// <summary> /// Initializes the Organizations client object and then calls the /// AttachPolicyAsync method to attach the policy to the root /// organization. /// </summary> public static async Task Main() { IAmazonOrganizations client = new AmazonOrganizationsClient(); var policyId = "p-00000000"; var targetId = "r-0000"; var request = new AttachPolicyRequest { PolicyId = policyId, TargetId = targetId, }; var response = await client.AttachPolicyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully attached Policy ID {policyId} to Target ID: {targetId}."); } else { Console.WriteLine("Was not successful in attaching the policy."); } } }
  • 如需 API 詳細資訊,請參閱 AWS SDK for .NET API 參考AttachPolicy中的。

CLI
AWS CLI

將策略附加到根、OU 或帳號

範例 1

下列範例顯示如何將服務控制原則 (SCP) 附加至 OU:

aws organizations attach-policy --policy-id p-examplepolicyid111 --target-id ou-examplerootid111-exampleouid111

範例 2

下列範例顯示如何將服務控制原則直接附加至帳戶:

aws organizations attach-policy --policy-id p-examplepolicyid111 --target-id 333333333333
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考AttachPolicy中的。

Python
適用於 Python (Boto3) 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

def attach_policy(policy_id, target_id, orgs_client): """ Attaches a policy to a target. The target is an organization root, account, or organizational unit. :param policy_id: The ID of the policy to attach. :param target_id: The ID of the resources to attach the policy to. :param orgs_client: The Boto3 Organizations client. """ try: orgs_client.attach_policy(PolicyId=policy_id, TargetId=target_id) logger.info("Attached policy %s to target %s.", policy_id, target_id) except ClientError: logger.exception( "Couldn't attach policy %s to target %s.", policy_id, target_id ) raise
  • 如需 API 的詳細資訊,請參閱AWS 開發套件AttachPolicy中的 Python (博托 3) API 參考。

政策變更會立即生效

後續作業

連接標籤政策之後,您可以了解您的資源遵從該標籤政策的情形。若要執行此操作,請使用 Resource Groups 主控台。如需詳細資訊,請參閱標記 AWS 資源使用指南中的評估帳號的符合性。

分離標籤政策

登入組織的管理帳戶後,您可以將標籤政策從原本連接的組織根、OU 或帳戶中分離。從實體分離標籤政策後,該政策即不再套用至現在已分離的實體所影響的任何帳戶。若要分離政策,請完成下列步驟。

最低許可

若要從組織根、OU 或帳戶中分離標籤政策,您必須具有執行下列動作的許可:

  • organizations:DetachPolicy

您可以導覽至政策或分離接政策的根、OU 或帳戶,以分離標籤政策。

導覽至連接的根、OU 或帳戶以分離標籤政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. AWS 帳戶 頁面導覽至您要從中分離政策的根、OU 或帳戶。您可能需要展開 OU (選擇 ),以尋找您所需的 OU 和帳戶。選擇根、OU 或帳戶的名稱。

  3. Policies (政策) 索引標籤上,選擇您要分離的標籤政策旁邊的選項按鈕,然後選擇 Detach (分離)。

  4. 在確認對話方塊中,選擇 Detach policy (分離政策)。

    連接的標籤政策清單會隨即更新。政策變更會立即生效。

導覽至標籤政策以分離備份政策
  1. 登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。

  2. Tag policies (標籤政策) 頁面上,選擇您要從根、OU 或帳戶分離的政策名稱。

  3. Targets (目標) 索引標籤上,選擇您要分離政策的根、OU 或帳戶旁的選項按鈕。您可能需要展開 OU (選擇 ),以尋找您所需的 OU 和帳戶。

  4. 請選擇分離

  5. 在確認對話方塊中,選擇 Detach (分離)。

    連接的標籤政策清單會隨即更新。政策變更會立即生效。

從組織根目錄、OU 或帳號中斷連結標籤策略

下列程式碼範例會示範如何使用DetachPolicy

.NET
AWS SDK for .NET
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Shows how to detach a policy from an AWS Organizations organization, /// organizational unit, or account. /// </summary> public class DetachPolicy { /// <summary> /// Initializes the Organizations client object and uses it to call /// DetachPolicyAsync to detach the policy. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var policyId = "p-00000000"; var targetId = "r-0000"; var request = new DetachPolicyRequest { PolicyId = policyId, TargetId = targetId, }; var response = await client.DetachPolicyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully detached policy with Policy Id: {policyId}."); } else { Console.WriteLine("Could not detach the policy."); } } }
  • 如需 API 詳細資訊,請參閱 AWS SDK for .NET API 參考DetachPolicy中的。

CLI
AWS CLI

從根、OU 或帳號中斷連結策略

下列範例顯示如何從 OU 中斷連結原則:

aws organizations detach-policy --target-id ou-examplerootid111-exampleouid111 --policy-id p-examplepolicyid111
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DetachPolicy中的。

Python
適用於 Python (Boto3) 的 SDK
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在AWS 設定和執行程式碼範例儲存庫

def detach_policy(policy_id, target_id, orgs_client): """ Detaches a policy from a target. :param policy_id: The ID of the policy to detach. :param target_id: The ID of the resource where the policy is currently attached. :param orgs_client: The Boto3 Organizations client. """ try: orgs_client.detach_policy(PolicyId=policy_id, TargetId=target_id) logger.info("Detached policy %s from target %s.", policy_id, target_id) except ClientError: logger.exception( "Couldn't detach policy %s from target %s.", policy_id, target_id ) raise
  • 如需 API 的詳細資訊,請參閱AWS 開發套件DetachPolicy中的 Python (博托 3) API 參考。

政策變更會立即生效。