3 ms·
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.
by nathancahill 7y ago
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.
- weiming 7y agoYep. AWS commands take the --profile argument to choose one of the items from the credentials file.
- nicoburns 7y agoYou 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 }