与 Amazon SDK或DetachPolicy一起使用 CLI - Amazon Organizations
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 Amazon SDK或DetachPolicy一起使用 CLI

以下代码示例演示如何使用 DetachPolicy

.NET
Amazon SDK for .NET
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

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详细信息,请参阅 “Amazon SDK for .NET API参考 DetachPolicy” 中的。

CLI
Amazon CLI

从根、OU 或账户分离策略

以下示例演示了如何从 OU 分离策略:

aws organizations detach-policy --target-id ou-examplerootid111-exampleouid111 --policy-id p-examplepolicyid111
  • 有关API详细信息,请参阅Amazon CLI 命令参考DetachPolicy中的。

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

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详细信息,请参阅DetachPolicy中的 Amazon SDKPython (Boto3) API 参考。

有关 Amazon SDK开发者指南和代码示例的完整列表,请参阅使用 Amazon Organizations 用一个 Amazon SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。