A small CLI tool for setting and switch default AWS profiles
Find a file
2025-10-06 16:16:37 +01:00
testdata mvp 2025-10-06 16:16:37 +01:00
.gitignore mvp 2025-10-06 16:16:37 +01:00
config.go mvp 2025-10-06 16:16:37 +01:00
config_test.go mvp 2025-10-06 16:16:37 +01:00
example-config.ini mvp 2025-10-06 16:16:37 +01:00
go.mod mvp 2025-10-06 16:16:37 +01:00
go.sum mvp 2025-10-06 16:16:37 +01:00
LICENSE mvp 2025-10-06 16:16:37 +01:00
main.go mvp 2025-10-06 16:16:37 +01:00
Makefile mvp 2025-10-06 16:16:37 +01:00
README.md mvp 2025-10-06 16:16:37 +01:00
selector.go mvp 2025-10-06 16:16:37 +01:00

AWSP - AWS Profile Switcher

A simple CLI tool for managing AWS SSO profiles by editing the ~/.aws/config file.

Features

  • Interactive profile switching with keyboard navigation
  • Display SSO session URLs for easy reference
  • Automatic backup before config changes
  • Minimal modifications to config file

Installation

Prerequisites

  • Go 1.24 or later
  • AWS CLI configured with SSO profiles

Building from Source

  1. Clone or navigate to the repository:
cd awsp
  1. Download dependencies:
make deps
  1. Build the binary:
make build
  1. (Optional) Install to your PATH:

Install to /usr/local/bin (requires sudo):

make install

Or install to ~/bin (no sudo required):

make install-user
# Make sure ~/bin is in your PATH

Usage

Interactive Profile Selection

Run awsp without arguments to see an interactive list of your AWS profiles:

awsp

Use the arrow keys (↑/↓) or vim keys (j/k) to navigate, then press Enter or Space to select a profile.

The tool will:

  • Display all SSO sessions with their start URLs
  • Show all available SSO profiles
  • Highlight the currently active default profile
  • Allow you to select a new default profile

Clear Default Profile

Remove the default profile configuration:

awsp clear

This removes the SSO configuration from the [default] section while preserving other settings like region.

How It Works

When you select a profile, awsp copies the following fields to the [default] section in ~/.aws/config:

  • sso_session
  • sso_account_id
  • sso_role_name

Other fields in the [default] section (like region) are preserved.

Backups

Before making any changes, awsp creates a backup at ~/.aws/config.awsp.backup. Only one backup is maintained - it's overwritten on each change.

Requirements

  • AWS config file must exist at ~/.aws/config
  • At least one SSO session must be configured
  • Profiles must use SSO-based authentication

If you haven't set up AWS SSO yet, follow the AWS CLI configuration guide.

Example AWS Config

[sso-session my-sso]
sso_start_url = https://my-company.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access

[profile dev]
sso_session = my-sso
sso_account_id = 123456789012
sso_role_name = DeveloperRole
region = us-west-2

[profile prod]
sso_session = my-sso
sso_account_id = 987654321098
sso_role_name = AdminRole
region = us-east-1

Building for Multiple Platforms

Build for all supported platforms at once:

make build-all

This creates binaries in the bin/ directory for:

  • macOS (Intel and Apple Silicon)
  • Linux (amd64 and arm64)

Development

make help          # Show all available make targets
make fmt           # Format code
make vet           # Run go vet
make lint          # Run formatting and vetting
make test          # Run tests
make test-coverage # Run tests with coverage report
make clean         # Remove built binaries

Testing

The project includes tests for the core configuration management logic:

# Run all tests
make test

# Run tests with coverage report
make test-coverage

Troubleshooting

"AWS config file not found"

Make sure you have ~/.aws/config file created. Run aws configure sso to set up your first profile.

"No SSO sessions found"

This tool only supports SSO-based authentication. Make sure your config file has [sso-session] sections defined.

"No SSO profiles found"

Ensure your profiles have the required SSO fields: sso_session, sso_account_id, and sso_role_name.