Search code examples
amazon-web-servicesamazon-iamaws-policies

Is there a way to delete a number of AWS IAM customer managed policies in one shot using CLI or GUI?


I am trying to delete all of my customer managed policies but I am not able to figure out a way to delete all of them in one click or using only one command


Solution

  • #!/bin/sh
    
    customer_managed_policy_arns=`aws iam list-policies --scope Local --query 'Policies[*].Arn' --output text`
    for arn in $customer_managed_policy_arns; do
        echo aws iam delete-policy --policy-arn "$arn"
    done
    

    Make sure you delete echo after you confirm all the commands you are expecting it to run.