Easily switch between AWS Profiles using an interactive selector.
This is a rewrite of awsp by johnnyopao in Go, with minor improvements.
The AWS CLI uses the profile defined in the AWS_PROFILE
environment variable if no specific profile flag is set.
Using a combination of a sourced script and a Go application, this tool parses the current AWS configuration (typically ~/.aws/config
). It then provides a filterable list and sets the AWS_PROFILE
environment variable based on your selection.
Set up any number of profiles using the AWS CLI.
aws configure --profile PROFILE_NAME
You can also leave off the --profile PROFILE_NAME
parameter to set your default
credentials.
Refer to the AWS CLI Documentation for more information.
The AWS Profile Switcher can be installed on macOS, Linux, or Windows, and works with most standard shells, including PowerShell.
In non-PowerShell shells, an alias is needed because _source-awsp.sh
must be sourced to modify the parent shell's environment variables.
-
brew install abyss/tools/awsp
-
Add the following to your shell profile (e.g.,
.bashrc
or.zshrc
):
alias awsp='source "$(brew --prefix awsp)/_source-awsp.sh"'
- Download the
go-awsp
binary from the releases page and include it in your PATH. - Place the script
_source-awsp.sh
in a known directory, such as~/bin
. - Add the following to your shell profile (e.g.,
.bashrc
or.zshrc
), including the full path to_source-awsp.sh
:
alias awsp="source ~/bin/_source-awsp.sh"
- Download the
go-awsp
binary from the releases page and include it in your PATH. - Put
awsp.ps1
in your PATH.
Dot sourcing is not necessary in PowerShell when using this script.
If AWS Tools for PowerShell is installed, it will also attempt to set the default profile using Set-AWSCredential
.
To use the interactive profile switcher, simply run awsp
and select a profile.
awsp
You can type to filter the list or use the arrow keys to navigate through the options. Press <Enter> to select the highlighted profile.
You can also specify a profile with the command to switch immediately:
awsp development
This is equivalent to directly running export AWS_PROFILE='development'
.
For better visibility into which AWS Profile is selected, it's helpful to configure your prompt to show the value of the environment variable AWS_PROFILE
.
Here is a simplified example: Add this to your shell profile (e.g., .bashrc
or .zshrc
):
function aws_profile {
local profile="${AWS_PROFILE:=default}"
echo "aws:(${profile})"
}
PS1="$PS1 \$(aws_profile)"
Here is @johnnyopao's example, which requires Oh My Zsh and includes color customization:
function aws_prof {
local profile="${AWS_PROFILE:=default}"
echo "%{$fg_bold[blue]%}aws:(%{$fg[yellow]%}${profile}%{$fg_bold[blue]%})%{$reset_color%} "
}
PROMPT='$PROMPT $(aws_prof)'
A more advanced example for Bash can be found in my dotfiles on GitHub.
Contributions in the form of issues and pull requests are welcome. 😄
This project is licensed under the ISC License.
Copyright (c) 2024 Abyss