Created
April 21, 2017 11:00
-
-
Save nyango/d3ccd153da19ceec3b4e0ca87a3de633 to your computer and use it in GitHub Desktop.
ユーザーに付与された管理ポリシー一覧を閲覧するシェルスクリプト
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 -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