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