Re:Show HN: A programmable tooltip on Mac OS
by nathancahill on Monday April 20, 2020 @03:02AM
(#22921788)
Can you use the profiles in ~/.aws/credentials? This is my lifeblood as a freelancer working with many clients and switching AWS accounts all day.
[ Parent
| on HN ]
Re:Show HN: A programmable tooltip on Mac OS
by weiming on Monday April 20, 2020 @06:48AM
(#22922728)
Yep. AWS commands take the --profile argument to choose one of the items from the credentials file.
Re:Show HN: A programmable tooltip on Mac OS
by nicoburns on Monday April 20, 2020 @07:12AM
(#22922850)
You can also use the following bash/zsh function to quickly set the current default profile (requires ruby):
function aws_switch () {
local env="$1"
local region="$2"
export AWS_DEFAULT_PROFILE="$env"
export AWS_ENV="$env"
export KITCHEN_ENV="$env"
export AWS_ACCESS_KEY_ID=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'credentials'))[ENV['AWS_DEFAULT_PROFILE']]['aws_access_key_id']")
export AWS_SECRET_ACCESS_KEY=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'credentials'))[ENV['AWS_DEFAULT_PROFILE']]['aws_secret_access_key']")
if [ -z "$region" ]
then
export AWS_REGION=$(/usr/bin/env ruby -e "require 'inifile'; puts IniFile.load(File.join(File.expand_path('~'), '.aws', 'config'))['profile ' + ENV['AWS_DEFAULT_PROFILE']]['region']")
else
export AWS_REGION="$region"
fi
export AWS_DEFAULT_REGION=$AWS_REGION
}