diff --git a/.aliases b/.aliases index ff53b9b..d0bcde9 100644 --- a/.aliases +++ b/.aliases @@ -133,3 +133,9 @@ alias reload="exec ${SHELL} -l" # Print each PATH entry on a separate line alias path='echo -e ${PATH//:/\\n}' + +# AWS aliases for profile management +. ~/bin/awsAliases +alias awsall="_awsListAll" +alias awsp="_awsSwitchProfile" +alias awswho="aws configure list" diff --git a/.bash_profile b/.bash_profile index 48e61c4..fa4eaa9 100644 --- a/.bash_profile +++ b/.bash_profile @@ -22,8 +22,3 @@ wttr() [ "$(tput cols)" -lt 125 ] && request+='?n' curl -H "Accept-Language: ${LANG%_*}" --compressed "$request" } - -. ~/bin/awsAliases -alias awsall="_awsListAll" -alias awsp="_awsSwitchProfile" -alias awswho="aws configure list" diff --git a/.gitignore b/.gitignore index 958a6ee..ad033ce 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ !.digrc !config !config/* +!bin/* +!bin diff --git a/bin/awsAliases b/bin/awsAliases new file mode 100644 index 0000000..6750e22 --- /dev/null +++ b/bin/awsAliases @@ -0,0 +1,26 @@ +#!/bin/bash + +function _awsListAll() { + + credentialFileLocation=${AWS_SHARED_CREDENTIALS_FILE}; + if [ -z $credentialFileLocation ]; then + credentialFileLocation=~/.aws/credentials + fi + + while read line; do + if [[ $line == "["* ]]; then echo "$line"; fi; + done < $credentialFileLocation; +}; + +function _awsSwitchProfile() { + if [ -z $1 ]; then echo "Usage: awsp profilename"; return; fi + + exists="$(aws configure get aws_access_key_id --profile $1)" + if [[ -n $exists ]]; then + export AWS_DEFAULT_PROFILE=$1; + export AWS_PROFILE=$1; + export AWS_REGION=$(aws configure get region --profile $1); + echo "Switched to AWS Profile: $1"; + aws configure list + fi +};