Last active
September 7, 2021 08:00
-
-
Save pataiji/88b2378f6b5a7b25da4bfd3a7f7bf812 to your computer and use it in GitHub Desktop.
List IAM User Policies
This file contains hidden or 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 | |
users=$(aws iam list-users --query 'Users[].UserName' --output text) | |
for user in $users; do | |
mkdir -p "$user" | |
policyNames=$(aws iam list-user-policies --user-name "$user" --query 'PolicyNames[]' --output text) | |
for policyName in $policyNames; do | |
aws iam get-user-policy --user-name "$user" --policy-name "$policyName" --output json > "${user}/${policyName}" | |
done | |
attachedPolicyArns=$(aws iam list-attached-user-policies --user-name "$user" --query 'AttachedPolicies[].PolicyArn' --output text) | |
for policyArn in $attachedPolicyArns; do | |
aws iam get-policy --policy-arn "$policyArn" --output json > "iam_user_policies/${user}/$(basename ${policyArn})" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment