本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
連接和卸離備份政策
您可以在整個組織及組織單位 (OU) 和個別帳戶上使用備份政策。請謹記以下幾點:
-
將備份政策連接至組織根時,此政策會套用至該根的所有成員 OU 和帳戶。
-
將備份政策連接至 OU 時,該政策會套用至屬於 OU 或其任何子 OU 的帳戶。這些帳戶也受制於連接至組織根的任何政策。
-
將備份政策連接至帳戶時,該政策只會套用至該帳戶。帳戶也受制於連接至組織根的任何政策及帳戶所屬的任何 OU。
帳戶從根和父 OU 繼承的任何備份政策集合,以及直接連接至帳戶的任何政策,即為有效政策。如需有關如何將政策合併為有效政策的資訊,請參閱理解管理政策繼承。
連接備份政策
登入組織的管理帳戶時,您可以將備份政策連接至組織的根、OU 或直接連接至帳戶。
您可以導覽至政策或連接政策的根、OU 或帳戶,以連接備份政策。
導覽至根、OU 或帳戶以連接備份政策
-
登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。
-
在 AWS 帳戶 頁面上,導覽至您要連接政策的根、OU 或帳戶的名稱並選擇。您可能需要展開 OU (選擇
),以尋找您所需的 OU 和帳戶。
-
在 Policies (政策) 索引標籤的 Backup policies (備份政策) 項目中,選擇 Attach (連接)。
-
尋找您所需的政策,然後選擇 Attach policy (連接政策)。
Policies (政策) 索引標籤上的連接的備份政策清單會更新,以包含新的新增項目。政策變更會立即生效。
導覽至政策以連接備份政策
-
登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。
-
在 Backup policies (備份政策) 頁面上,選擇您要連接的政策名稱。
-
在 Targets (目標) 索引標籤上,選擇 Attach (連接)。
-
選擇您要連接政策的根、OU 或帳戶旁的選項按鈕。您可能需要展開 OU (選擇
),以尋找您所需的 OU 和帳戶。
-
選擇連接政策。
Targets (目標) 索引標籤上的連接的備份政策清單會更新,以包含新的新增項目。政策變更會立即生效。
將備份原則附加至組織根目錄、OU 或帳戶
下列程式碼範例會示範如何使用AttachPolicy
。
- .NET
-
- AWS SDK for .NET
-
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.");
}
}
}
- 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
- Python
-
- 適用於 Python (Boto3) 的 SDK
-
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
政策變更會立即生效
卸離備份政策
登入組織的管理帳戶後,您可以將備份政策從原本連接的組織根、OU 或帳戶分離。從實體分離備份政策後,該政策即不再套用至現在已分離的實體先前所影響的任何帳戶。若要分離政策,請完成下列步驟。
若要從組織根、OU 或帳戶分離備份政策,您必須具有執行下列動作的許可:
您可以導覽至政策或分離接政策的根、OU 或帳戶,以分離備份政策。
導覽至連接的根、OU 或帳戶以分離備份政策
-
登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。
-
在 AWS 帳戶 頁面導覽至您要從中分離政策的根、OU 或帳戶。您可能需要展開 OU (選擇
),以尋找您所需的 OU 和帳戶。選擇根、OU 或帳戶的名稱。
-
在 Policies (政策) 索引標籤上,選擇您要分離的備份政策旁邊的選項按鈕,然後選擇 Detach (分離)。
-
在確認對話方塊中,選擇 Detach policy (分離政策)。
連接的備份政策清單會隨即更新。政策變更會立即生效。
導覽至政策以分離備份政策
-
登入 AWS Organizations 主控台。您必須以 IAM 使用者登入、擔任 IAM 角色,或是以組織管理帳戶中的根使用者 (不建議) 身分登入。
-
在 Backup policies (備份政策) 頁面上,選擇您要從根、OU 或帳戶分離的政策名稱。
-
在 Targets (目標) 索引標籤上,選擇您要分離政策的根、OU 或帳戶旁的選項按鈕。您可能需要展開 OU (選擇
),以尋找您所需的 OU 和帳戶。
-
請選擇分離。
-
在確認對話方塊中,選擇 Detach (分離)。
連接的備份政策清單會隨即更新。政策變更會立即生效。
從組織根目錄、OU 或帳戶中斷連結備份策略
下列程式碼範例會示範如何使用DetachPolicy
。
- .NET
-
- AWS SDK for .NET
-
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.");
}
}
}
- CLI
-
- AWS CLI
-
從根、OU 或帳號中斷連結策略
下列範例顯示如何從 OU 中斷連結原則:
aws organizations detach-policy --target-id ou-examplerootid111-exampleouid111 --policy-id p-examplepolicyid111
- Python
-
- 適用於 Python (Boto3) 的 SDK
-
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
政策變更會立即生效。