Created
February 7, 2018 07:17
-
-
Save rupertbg/bfe57ff5c4afcf6e23f85904e7498474 to your computer and use it in GitHub Desktop.
AWS CLI delete policies including all versions (requires jq)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euxo pipefail; | |
policies=$(cat ./policies.txt); # A new-line separated list of policy ARNs | |
for policy in $policies; do | |
policiesVersions="$(aws iam list-policy-versions --policy-arn "$policy" | jq -r ".Versions[] | select(.IsDefaultVersion == false) | .VersionId")"; | |
for pv in $policiesVersions; do | |
aws iam delete-policy-version --policy-arn "$policy" --version-id $pv; | |
done; | |
aws iam delete-policy --policy-arn "$policy"; | |
done; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment