awsctx switches the active AWS SSO profile in your current shell.
It reads SSO profiles from the AWS CLI config file, provides a searchable list, and updates AWS_PROFILE for your current shell session.
awsctx expects your AWS CLI config file (typically ~/.aws/config) to contain AWS SSO profiles. These profiles should include fields such as sso_session, sso_account_id, and sso_role_name. See public/tapes/demo-aws-config for a reference example.
To test awsctx without modifying your actual configuration, you can point AWS_CONFIG_FILE to a separate file:
export AWS_CONFIG_FILE="$PWD/public/tapes/demo-aws-config"Prebuilt binaries are available for macOS and Linux. Native Windows support is not yet available; please use WSL or build from source if you wish to experiment on Windows.
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/lemtoc/awsctx/releases/download/v0.2.0/awsctx-installer.sh | shbrew install lemtoc/tap/awsctxmise use -g github:lemtoc/awsctxcargo install --git https://github.com/lemtoc/awsctxShell integration is required for awsctx to modify the AWS_PROFILE variable in your current session.
Run the appropriate command for your shell to set it up automatically:
- zsh:
awsctx init zsh - bash:
awsctx init bash - fish:
awsctx init fish
If you prefer to manage your shell configuration manually, add the following to your startup script:
zsh / bash:
eval "$(awsctx activate zsh)"eval "$(awsctx activate bash)"fish:
awsctx activate fish | sourceIf you prefer typing aws sso switch over awsctx, use the --aws-wrapper flag. This defines an aws() shell function that intercepts the aws sso switch command while forwarding all other calls to the real AWS CLI:
awsctx init zsh --aws-wrapper
awsctx init bash --aws-wrapperawsctx init fish --aws-wrapperWith the wrapper enabled, you can use the following:
aws sso switch # interactive selection
aws sso switch prod-admin # switch by exact name
aws sso sw prod-admin # `sw` is a shorter alias for `switch`This is opt-in because it wraps the aws command. If an aws alias or function already exists, awsctx will print a warning and leave it untouched.
No. The wrapper is a lightweight shell function:
- Preserves existing wrappers: It won't override existing
awsaliases or functions (like those fromaws-vault). - Negligible overhead: For commands other than
sso switch/sw, it runs a few shell builtin checks and immediately executes the real AWS CLI. - Transparent forwarding: Arguments, stdin/stdout, pipes, and exit codes are forwarded unchanged.
- Interactive only: It only loads in interactive sessions and won't affect non-interactive scripts or CI/CD pipelines.
Run awsctx to select a profile interactively:
awsctxOn success, AWS_PROFILE is updated in the current shell:
Switched to prod-admin.
Switch to a specific profile:
awsctx prod-adminYou can narrow down the list using environment variables:
export AWS_PROFILE_PREFIX=prod-
awsctxexport AWS_ACCOUNT_ID=111122223333
awsctxWhen both filters are set, awsctx only shows profiles that match both.
To bypass filters, use the --all flag:
awsctx --allList matching profiles without changing your current environment:
awsctx listNAME ACCOUNT_ID ROLE REGION
────────── ──────────── ────────────────────── ──────────────
prod-admin 111122223333 AWSAdministratorAccess ap-northeast-1
dev-admin 444455556666 AWSAdministratorAccess ap-northeast-1
List all profiles, ignoring filters:
awsctx list --allPrint JSON:
awsctx list --json[
{
"name": "prod-admin",
"sso_account_id": "111122223333",
"sso_role_name": "AWSAdministratorAccess",
"sso_session": "sso",
"region": "ap-northeast-1",
"output": "json"
}
]Authenticate and then switch:
awsctx loginLogin to a specific profile:
awsctx login prod-adminTo login without switching the active profile:
awsctx login --no-switchawsctx login --no-switch prod-adminIgnore filters when choosing the login profile:
awsctx login --allawsctx specifically targets AWS CLI profiles managed via IAM Identity Center. A profile is recognized if it contains:
sso_sessionsso_account_idsso_role_name
Note
[sso-session ...] sections and profiles using credential_process are currently ignored.
