Skip to content

Instantly share code, notes, and snippets.

@RecuencoJones
Created April 27, 2020 10:33
Show Gist options
  • Save RecuencoJones/3c304a7f935d701462d24e71581d59a2 to your computer and use it in GitHub Desktop.
Save RecuencoJones/3c304a7f935d701462d24e71581d59a2 to your computer and use it in GitHub Desktop.
Set AWS_PROFILE in current shell
alias aws-profile='. ~/.aws/set-profile'
#!/usr/bin/env bash
_aws_profiles=`cat ${HOME}/.aws/credentials | grep '\[' | tr -d '[]'`
_aws_profiles_formatted=`echo ${_aws_profiles} | tr '\n' ' '`
if [[ -z $1 ]]; then
echo "Missing profile name, should be one of: ${_aws_profiles_formatted}"
elif [[ -z `echo "${_aws_profiles}" | grep -e "^${1}$"` ]]; then
echo "Profile name does not exist, should be one of: ${_aws_profiles_formatted}"
else
eval "export AWS_PROFILE=${1:-default}"
echo "Now using AWS profile: ${AWS_PROFILE}"
fi
unset _aws_profiles
unset _aws_profiles_formatted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment