搭DeletePolicy配 AWS SDK或使用 CLI - AWS Organizations

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

DeletePolicy配 AWS SDK或使用 CLI

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

.NET
AWS SDK for .NET
注意

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

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Deletes an existing AWS Organizations policy. /// </summary> public class DeletePolicy { /// <summary> /// Initializes the Organizations client object and then uses it to /// delete the policy with the specified policyId. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var policyId = "p-00000000"; var request = new DeletePolicyRequest { PolicyId = policyId, }; var response = await client.DeletePolicyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully deleted Policy: {policyId}."); } else { Console.WriteLine($"Could not delete Policy: {policyId}."); } } }
  • 如需詳API細資訊,請參閱AWS SDK for .NET API參考DeletePolicy中的。

CLI
AWS CLI

若要刪除策略

下列範例顯示如何從組織刪除策略。此範例假設您先前已將原則從所有實體中斷連結:

aws organizations delete-policy --policy-id p-examplepolicyid111
  • 如需詳API細資訊,請參閱AWS CLI 指令參考DeletePolicy中的。

Python
SDK對於 Python(肉毒桿菌 3)
注意

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

def delete_policy(policy_id, orgs_client): """ Deletes a policy. :param policy_id: The ID of the policy to delete. :param orgs_client: The Boto3 Organizations client. """ try: orgs_client.delete_policy(PolicyId=policy_id) logger.info("Deleted policy %s.", policy_id) except ClientError: logger.exception("Couldn't delete policy %s.", policy_id) raise
  • 如需詳API細資訊,請參閱DeletePolicyAWS SDK的〈〉以取得 Python (Boto3) API 參考資料。

如需 AWS SDK開發人員指南和程式碼範例的完整清單,請參閱使用 AWS Organizations 用一個 AWS SDK。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。