Last active
November 11, 2022 07:30
-
-
Save schan90/f47dd3480da1c731ab548fa9dfa7a1bf to your computer and use it in GitHub Desktop.
aws-key-switch.rc.conf
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
# ~/.bashrc or ~/.zshrc | |
... | |
############ for aws credentials set: made by schan V1.2.0 ########### | |
DEFAULT_PF="your-aws-profile" | |
PF="" | |
aws_profile() | |
{ | |
if [[ -n $AWS_PROFILE ]]; then | |
echo ${AWS_PROFILE} | |
else | |
echo "Don't have a AWS-KEY" | |
fi | |
} | |
asking_pf() | |
{ | |
echo -n " | |
which AWS-PROFILE do you want? : | |
$(cat ~/.aws/credentials | grep -o '\[[^]]*\]') | |
If NO input & press ENTER, using ${DEFAULT_PF} ~! | |
input >>> | |
" | |
read REPLY | |
[[ "${REPLY}" = "" ]] && selc_pf="${DEFAULT_PF}" || selc_pf="${REPLY}" | |
PF="${selc_pf}" | |
} | |
aws_set() | |
{ | |
[[ "$1" = "" ]] && { asking_pf; pf="${PF}"; } || pf="$1" | |
[[ $(cat ~/.aws/credentials | grep "\[${pf}\]") ]] && {export AWS_PROFILE=${pf}; echo "using ${AWS_PROFILE} AWS-PROFILE ..."} \ | |
|| {echo "\n ***** Invalid profile name ***** \n"; aws_set; } | |
} | |
alias aws-key='aws_profile' | |
alias aws-set='aws_set $1' | |
alias aws-clear='export AWS_PROFILE=' | |
alias aws-config='aws configure list' | |
alias aws-sts='aws sts get-caller-identity' | |
alias aws-list="cat ~/.aws/credentials | grep -o '\[[^]]*\]' " | |
####### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment