Úselo DetachPolicy con un AWS SDK o CLI - AWS Ejemplos de código de SDK

Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK.

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Úselo DetachPolicy con un AWS SDK o CLI

Los siguientes ejemplos de código muestran cómo utilizar DetachPolicy.

.NET
SDK para .NET
nota

Hay más en marcha GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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."); } } }
  • Para obtener más información sobre la API, consulta DetachPolicyla Referencia AWS SDK para .NET de la API.

CLI
AWS CLI

Desasociación de una política de un nodo raíz, unidad organizativa o cuenta

En el siguiente ejemplo se muestra cómo desasociar una política de una unidad organizativa:

aws organizations detach-policy --target-id ou-examplerootid111-exampleouid111 --policy-id p-examplepolicyid111
  • Para obtener más información sobre la API, consulta DetachPolicyla Referencia de AWS CLI comandos.

Python
SDK para Python (Boto3)
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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
  • Para obtener más información sobre la API, consulta DetachPolicyla AWS Referencia de API de SDK for Python (Boto3).

SAP ABAP
SDK para SAP ABAP
nota

Hay más información al respecto. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

TRY. lo_org->detachpolicy( iv_policyid = iv_policy_id iv_targetid = iv_target_id ). MESSAGE 'Policy detached from target.' TYPE 'I'. CATCH /aws1/cx_orgaccessdeniedex. MESSAGE 'You do not have permission to detach the policy.' TYPE 'E'. CATCH /aws1/cx_orgpolicynotfoundex. MESSAGE 'The specified policy does not exist.' TYPE 'E'. CATCH /aws1/cx_orgtargetnotfoundex. MESSAGE 'The specified target does not exist.' TYPE 'E'. CATCH /aws1/cx_orgpolicynotattex. MESSAGE 'The policy is not attached to the target.' TYPE 'E'. ENDTRY.
  • Para obtener más información sobre la API, consulte DetachPolicyla referencia sobre la API ABAP del AWS SDK para SAP.