Utilisation DeletePolicy avec un AWS SDK ou une CLI - AWS Exemples de code SDK

D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Utilisation DeletePolicy avec un AWS SDK ou une CLI

Les exemples de code suivants illustrent comment utiliser DeletePolicy.

.NET
SDK pour .NET
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code 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}."); } } }
  • Pour plus de détails sur l'API, reportez-vous DeletePolicyà la section Référence des AWS SDK pour .NET API.

CLI
AWS CLI

Pour supprimer une politique

L’exemple suivant montre comment supprimer une stratégie d’une organisation. L’exemple suppose que vous avez préalablement détaché la stratégie de toutes les entités :

aws organizations delete-policy --policy-id p-examplepolicyid111
  • Pour plus de détails sur l'API, reportez-vous DeletePolicyà la section Référence des AWS CLI commandes.

Python
Kit SDK for Python (Boto3)
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code 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
  • Pour plus de détails sur l'API, consultez DeletePolicyle AWS manuel de référence de l'API SDK for Python (Boto3).

SAP ABAP
Kit SDK pour SAP ABAP
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

TRY. lo_org->deletepolicy( iv_policyid = iv_policy_id ). MESSAGE 'Policy deleted.' TYPE 'I'. CATCH /aws1/cx_orgaccessdeniedex. MESSAGE 'You do not have permission to delete the policy.' TYPE 'E'. CATCH /aws1/cx_orgpolicynotfoundex. MESSAGE 'The specified policy does not exist.' TYPE 'E'. CATCH /aws1/cx_orgpolicyinuseex. MESSAGE 'The policy is still attached to one or more targets.' TYPE 'E'. ENDTRY.
  • Pour plus de détails sur l'API, reportez-vous DeletePolicyà la section de référence du AWS SDK pour l'API SAP ABAP.