Last active
January 21, 2019 12:23
-
-
Save cm-watanabeseigo/92fa6ebebc4aaeec29a0262552c3531f to your computer and use it in GitHub Desktop.
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
[profile bastion] | |
region = ap-northeast-1 | |
[profile temp-operator] | |
region = ap-northeast-1 | |
[profile System1-Prod] | |
# System 1 - Production < bastion | |
role_arn = arn:aws:iam::666600006666:role/user-watanabe | |
source_profile = bastion | |
mfa_serial = arn:aws:iam::222200002222:mfa/user-watanabe | |
region = ap-northeast-1 | |
[profile System2-Prod] | |
role_arn = arn:aws:iam::444400004444:role/user-watanabe | |
source_profile = bastion | |
mfa_serial = arn:aws:iam::222200002222:mfa/user-watanabe | |
region = ap-northeast-1 | |
[profile System2-Dev] | |
role_arn = arn:aws:iam::999911119999:role/user-watanabe | |
source_profile = bastion | |
mfa_serial = arn:aws:iam::222200002222:mfa/user-watanabe | |
region = ap-northeast-1 | |
[profile System3-Prod] | |
role_arn = arn:aws:iam::333311113333:role/user-watanabe | |
source_profile = bastion | |
mfa_serial = arn:aws:iam::222200002222:mfa/user-watanabe | |
region = ap-northeast-1 | |
[profile cmp] | |
role_arn = arn:aws:iam::696900006969:role/user-watanabe | |
source_profile = bastion | |
mfa_serial = arn:aws:iam::222200002222:mfa/user-watanabe | |
region = ap-northeast-1 | |
[profile private] | |
region = ap-northeast-1 |
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
function aws-profile() { | |
# AWS Config ファイルのパス | |
local __AWS_CONFIG=$HOME/.aws/config | |
# profile 名のリスト選択 > 環境変数セット | |
$( | |
grep '^\[profile ' ${__AWS_CONFIG} | sed -e 's/^.* //' -e 's/\].*$//' \ | |
| fzf \ | |
--preview="sed -n -e '/\[profile {}/,/^$/p' ${__AWS_CONFIG}" \ | |
--layout=reverse \ | |
--height 15 --inline-info --border \ | |
--cycle \ | |
| sed -e 's/^/export AWS_PROFILE=/' | |
) | |
# 現状の出力 | |
printf "export AWS_PROFILE=\e[83;1m%s\e[m\n" "$AWS_PROFILE" | |
} |
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
# AWS Profile Selector | |
function aws-profile() { | |
# AWS Config ファイルのパス | |
local __AWS_CONFIG=${AWS_CONFIG_FILE:-$HOME/.aws/config} | |
# 現在の環境変数設定のクリア | |
unset-aws-profile --silence | |
# profile 名のリスト選択 > 環境変数セット | |
$( | |
grep '^\[profile ' ${__AWS_CONFIG} | sed -e 's/^.* //' -e 's/\].*$//' \ | |
| fzf --preview=" | |
echo $(echo ${__AWS_CONFIG} | sed -e 's|'${HOME}'|\\~|') | |
echo '----' | |
sed -n -e '/\[profile {}/,/^$/p' ${__AWS_CONFIG} | |
" \ | |
--layout=reverse \ | |
--height 15 --inline-info --border \ | |
--cycle --no-mouse \ | |
| sed -e 's/^/export AWS_PROFILE=/' | |
) | |
# 現状の出力 | |
if [ "$AWS_PROFILE" != "" ]; then | |
printf "export \e[93;1mAWS_PROFILE\e[m=\e[83;1m%s\e[m\n" "$AWS_PROFILE" >&2 | |
else | |
echo "AWS_PROFILE not set." >&2 | |
fi | |
} | |
# AWS Credential 環境変数のクリア | |
function unset-aws-profile() { | |
local __related_envs="$( echo ' | |
AWS_PROFILE AWS_DEFAULT_PROFILE | |
AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY | |
AWS_SESSION_TOKEN AWS_SESSION_EXPIRATION | |
AWS_DEFAULT_REGION | |
' | xargs)" | |
# 関連環境変数のクリア | |
unset ${__related_envs} | |
case "$1" in | |
-s|--silence) | |
;; | |
*) | |
echo "Unset : ${__related_envs}" >&2 | |
echo "" >&2 | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment