Skip to content

Instantly share code, notes, and snippets.

@nyango
Created April 21, 2017 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyango/d3ccd153da19ceec3b4e0ca87a3de633 to your computer and use it in GitHub Desktop.
Save nyango/d3ccd153da19ceec3b4e0ca87a3de633 to your computer and use it in GitHub Desktop.
ユーザーに付与された管理ポリシー一覧を閲覧するシェルスクリプト
#!/bin/bash -eu
if [[ $# != 1 ]];
then
echo "第一引数にアカウント名を指定してください。"
echo ""
echo "e.g."
echo "$ ./list_policies.sh your_account_name"
exit 1
fi
user_name=$1
if [[ "$(type jq > /dev/null && echo $?)" != "0" ]];
then
echo "jqコマンドが存在しません"
exit 1
fi
if [[ "$(type aws > /dev/null && echo $?)" != "0" ]];
then
echo "awsコマンドが存在しません"
exit 1
fi
for policyArn in $(aws iam list-attached-user-policies --user-name $user_name | jq -Mcr '.AttachedPolicies | .[] | .PolicyArn');
do
echo $policyArn
aws iam get-policy-version --policy-arn $policyArn --version-id $(aws iam get-policy --policy-arn $policyArn |jq -Mcr '.Policy.DefaultVersionId') | jq
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment