D’autres exemples de kits AWS SDK sont disponibles dans le référentiel GitHub AWS Doc SDK Examples
Utilisation de DetachPolicy avec un kit AWS SDK ou une interface de ligne de commande
Les exemples de code suivants illustrent comment utiliser DetachPolicy.
- .NET
-
- SDK pour .NET
-
Note
Il y en a plus sur 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> /// 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."); } } }-
Pour plus de détails sur l’API, consultez DetachPolicy dans la Référence des API du kit AWS SDK pour .NET.
-
- CLI
-
- AWS CLI
-
Pour détacher une politique d’une racine, d’une unité organisationnelle ou d’un compte
L’exemple suivant indique comment détacher une politique d’une unité organisationnelle :
aws organizations detach-policy --target-idou-examplerootid111-exampleouid111--policy-idp-examplepolicyid111-
Pour plus de détails sur l’API, consultez DetachPolicy
dans la Référence des commandes de l’AWS CLI.
-
- Python
-
- Kit SDK pour Python (Boto3)
-
Note
Il y en a plus sur 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 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-
Pour plus de détails sur l’API, consultez DetachPolicy dans la Référence des API du kit AWS SDK for Python (Boto3).
-