Ability to use different aws credentials profiles
libert-xyz opened this issue · comments
I manage multiple AWS accounts.
The AWS credentials are located in my local machine ~/.aws/credentials
where I have different profiles.
The should allow us to switch between AWS credentials profiles.
Switching between AWS profiles is easily done by setting AWS_PROFILE
environment variable.
If you want auto-completion, you can use a below code snippet. Add it to your .bashrc
, and modify according to your needs.
aws-profile() {
[ -z "$1" ] && unset AWS_PROFILE && return
export AWS_PROFILE="$1"
}
# (optional) auto-completion for aws-profile
_awsprofile_comp()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
LIST="$(sed -n '/^\[profile .*\]/s/\[profile \([^]]*\)\]/\1/p;$adefault' ~/.aws/config)"
COMPREPLY=( $( compgen -W "${LIST}" -- "$cur" ) )
} && complete -F _awsprofile_comp aws-profile
Switching between AWS profiles is easily done by setting
AWS_PROFILE
environment variable.If you want auto-completion, you can use a below code snippet. Add it to your
.bashrc
, and modify according to your needs.aws-profile() { [ -z "$1" ] && unset AWS_PROFILE && return export AWS_PROFILE="$1" } # (optional) auto-completion for aws-profile _awsprofile_comp() { local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" LIST="$(sed -n '/^\[profile .*\]/s/\[profile \([^]]*\)\]/\1/p;$adefault' ~/.aws/config)" COMPREPLY=( $( compgen -W "${LIST}" -- "$cur" ) ) } && complete -F _awsprofile_comp aws-profile
What about the region?
Switching between AWS profiles is easily done by setting
AWS_PROFILE
environment variable.If you want auto-completion, you can use a below code snippet. Add it to your
.bashrc
, and modify according to your needs.aws-profile() { [ -z "$1" ] && unset AWS_PROFILE && return export AWS_PROFILE="$1" } # (optional) auto-completion for aws-profile _awsprofile_comp() { local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" LIST="$(sed -n '/^\[profile .*\]/s/\[profile \([^]]*\)\]/\1/p;$adefault' ~/.aws/config)" COMPREPLY=( $( compgen -W "${LIST}" -- "$cur" ) ) } && complete -F _awsprofile_comp aws-profile
I like this.
I've not used aws profiles but I wonder whether it would be worth adding:
aws-profiles # list profles
aws-profile # display current profile
aws-profile PROFILE_NAME # set profile
They basically mirror the region commands.
I use zsh and I get "command not found: complete". I understand complete is for bash but not zsh. Is there a way to get this to work in zsh?