in Lambda/BackupOrgPolicyManager/src/BackupOrgPolicyManager.py [0:0]
def detach_policy_from_target_list(policy_target_list, policy_id, assumed_role_creds=None):
"""
Helper function to detach the specified policy from policy_target_list
"""
# Detach the policy in target accounts
org_client = boto3_client('organizations', AWS_REGION, assumed_role_creds)
for policy_target in policy_target_list:
try:
detach_policy(org_client, policy_id, policy_target)
except org_client.exceptions.PolicyInUseException:
time.sleep(int(1))
detach_policy(org_client, policy_id, policy_target)
except org_client.exceptions.PolicyNotAttachedException:
logger.info('Ignoring error to continue trying for further detachments.')