Easy Role Switching with awsume and peco
When managing multiple AWS accounts, switching between profiles can become tedious.
In this post, I introduce an interactive AWS profile selection script that combines awsume and peco.
Overview
This script provides the following features:
- Retrieves the list of profiles with
awsume -l - Lets you select interactively with
peco - Runs
awsumewith the selected profile to switch roles
Prerequisites
The following tools must be installed:
awsume: An AWS profile management toolpeco: A command-line selection tool- Profiles already configured in
~/.aws/credentials
Installation
1 | # awsume のインストール (例: pip経由) |
Implementing the Script
1 |
|
Usage
1 | # スクリプトを実行 |
When you run it, the list of configured profiles is displayed, and you can select one with the arrow keys and confirm with Enter.
Feature Details
Filtering
The following items are automatically excluded from the list:
- The
defaultprofile - Header lines (such as
==================================AWS) - Lines containing the
PROFILEstring - Empty lines
- Dash lines (such as
----)
Error Handling
- Checking for the existence of required commands
- Handling the case where no profile is found
- Handling the case where selection is canceled
- Suppressing warning messages
Script Flow
- Verify the existence of
awsumeandpeco - Retrieve the profile list with
awsume -l - Filter out unnecessary lines
- Display the selection screen with
peco - Run
awsumewith the selected profile
Notes
- If profile selection is canceled, the script exits normally
- On errors, it displays an appropriate message and exits
Conclusion
Using this script makes it possible to manage multiple AWS accounts efficiently. Especially in environments with many profiles, you should be able to appreciate the power of peco, which lets you make selections visually.
If you use awsume on a daily basis, give it a try.
I personally use it with an alias like alias a="$HOME/awsume-switcher.sh".
That’s all.
I hope this is helpful.
Easy Role Switching with awsume and peco
https://kenzo0107.github.io/en/2025/07/04/awsume-switch-role/