Interactive PowerShell tool for switching between AWS SSO profiles.
- Reads profiles from
~\.aws\configin file order, with optional A→Z / Z→A sort - Arrow key, Page Up/Down navigation with scrolling viewport
- Bordered interactive menu with key hints
- Sets
AWS_PROFILEin the current shell - Automatically triggers
aws sso login - Top-of-list
❌ Disconnect [profile@region]entry clears the local AWS session variables and runsaws sso logout
sap| Key | Action |
|---|---|
↑ / ↓ |
Move selection (wraps around top/bottom) |
PgUp / PgDn |
Jump half a page |
S |
Cycle sort mode (file order → A→Z → Z→A) |
Enter |
Select profile and login (or disconnect the current session) |
Esc |
Cancel |
The script defines a Switch-AwsProfile function and a sap alias. Dot-sourcing it once in $PROFILE loads both at shell startup — no wrapper function needed.
# Copy script to a persistent location
$scriptsDir = "$env:LOCALAPPDATA\Scripts"
New-Item -ItemType Directory -Path $scriptsDir -Force
Copy-Item .\Switch-AwsProfile.ps1 $scriptsDir\
# Append a dot-source line to $PROFILE
Add-Content -Path $PROFILE -Value "`n# AWS Profile Switcher`n. `"$scriptsDir\Switch-AwsProfile.ps1`""
# Load it now without restarting the shell
. $PROFILE-
Copy
Switch-AwsProfile.ps1to any permanent location, e.g.%LOCALAPPDATA%\Scripts\. -
Add one line to your PowerShell profile (
$PROFILE):. "$env:LOCALAPPDATA\Scripts\Switch-AwsProfile.ps1"
-
Reload:
. $PROFILE
Switch-AwsProfile and sap are now available in every new shell session.
- PowerShell 7+
- AWS CLI installed
- Configured AWS SSO profiles in
~\.aws\config
Oh My Posh enhances your PowerShell prompt with themes and AWS profile display.
A bash/zsh port is available as switch-aws-profile.sh.
# Copy to a directory in your PATH
mkdir -p ~/.local/bin
cp switch-aws-profile.sh ~/.local/bin/sap
chmod +x ~/.local/bin/sap
# Add a sourcing wrapper to ~/.bashrc or ~/.zshrc
echo 'sap() { source ~/.local/bin/sap; }' >> ~/.bashrc # or ~/.zshrc
source ~/.bashrc # or source ~/.zshrcThe wrapper sources the script so AWS_PROFILE persists in the current shell.
Note: Natural number sorting (
Admin-2beforeAdmin-10) requires GNU coreutilssort -V, available by default on Linux and via Homebrew (brew install coreutils) on macOS.
