Multi AWS tool for managing operations across multiple AWS accounts via SSO
Project description
MultiAWSTool
A command-line tool for managing multiple AWS accounts through AWS SSO. Execute AWS CLI commands across multiple accounts safely and efficiently with built-in security controls and parallel execution support.
Features
- Multi-account Operations: Execute AWS CLI commands across multiple accounts via SSO
- Automated Profile Management: Generate and manage AWS CLI profiles automatically
- Parallel & Sequential Execution: Choose between parallel (fast) or sequential (safe) execution modes
- Smart Output Management: Configurable output formatting with customizable file naming patterns
- Security Controls: Built-in protection against destructive operations with configurable overrides
- Shell Completion: Full shell completion support for bash, zsh, and fish
- Library Integration: Import as a Python library for use in other tools and scripts
Installation
Option 1: Install as Package (Recommended)
Install MultiAWSTool as a Python package to get the multi-aws command:
# Clone the repository
git clone <repository-url>
cd MultiAWSTool
# Install in development mode (creates multi-aws command)
pip install -e .
# Or install from PyPI when published
pip install multi-aws-tool
After installation, you can use the multi-aws command directly:
multi-aws --help
multi-aws configure
Publishing
PyPI publishing is handled by GitHub Actions. Publishing a GitHub release, or manually running the Publish to PyPI workflow, builds the package and uploads the generated distributions to PyPI using trusted publishing.
Before the workflow can publish successfully, configure the amahlaka/multi-aws-tool repository as a trusted publisher in PyPI and allow the pypi GitHub Actions environment to deploy.
Option 2: Development Setup
For development or if you prefer to run directly:
# Clone and setup
git clone <repository-url>
cd MultiAWSTool
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run directly
python main.py --help
Shell Completion Setup
Enable shell completion for better command-line experience:
# Generate completion script for your shell
multi-aws completion --shell zsh # or bash, fish
# For zsh, add to ~/.zshrc:
eval "$(_MULTI_AWS_COMPLETE=zsh_source multi-aws)"
# For bash, add to ~/.bashrc:
eval "$(_MULTI_AWS_COMPLETE=bash_source multi-aws)"
# Or install directly:
multi-aws completion --shell zsh > ~/.multi-aws-completion.zsh
echo "source ~/.multi-aws-completion.zsh" >> ~/.zshrc
Quick Start
-
Install the tool (see Installation section above)
-
Configure the tool:
multi-aws configure
- Initialize SSO and discover accounts:
multi-aws init --sso-session default
- Fetch roles for accounts:
multi-aws roles --accounts 123456789012,987654321098
- Generate AWS profiles:
multi-aws profiles --accounts 123456789012 --role PowerUserAccess --append-to-config
- Run commands across accounts:
multi-aws run 'sts get-caller-identity' --accounts 123456789012,987654321098
Advanced Usage Examples
Run commands in parallel with output saving:
multi-aws run 'ec2 describe-instances' --accounts all --parallel --save
Filter accounts by team and run with custom timeout:
multi-aws run 'iam list-users' --team production --timeout 60
Dry run to see what would be executed:
multi-aws run 'ec2 terminate-instances --instance-ids i-1234567890abcdef0' --accounts 123456789012 --dry-run
Commands
Core Commands
configure: Interactive setup of tool configurationinit: Initialize SSO authentication and discover AWS accountsroles: Fetch available IAM roles for specified accountsprofiles: Generate AWS CLI profiles for account/role combinationsrun: Execute AWS CLI commands across multiple accountssync: Sync profile names from AWS config to account data
Management Commands
cleanup: Remove tool-generated configurations (profiles, tokens, account data)clean-duplicates: Find and remove duplicate AWS profilessanitize-names: Clean account names for profile compatibilityassign-team: Assign product team labels to accountslist-team-accounts: List accounts by product team
Utility Commands
completion: Generate shell completion scripts
Command Examples
# Interactive configuration
multi-aws configure
# Discover accounts with specific SSO session
multi-aws init --sso-session my-sso-session
# Get roles for specific accounts
multi-aws roles --accounts 123456789012,987654321098
# Generate profiles and add to AWS config
multi-aws profiles --accounts 123456789012 --role PowerUserAccess --append-to-config
# Execute commands across all active accounts
multi-aws run 'sts get-caller-identity' --accounts all
# Execute in parallel with custom output directory
multi-aws run 'ec2 describe-regions' --accounts file:accounts.txt --parallel --output-dir ./results
# Assign team to accounts
multi-aws assign-team --accounts 123456789012,987654321098 --team backend-team
# List accounts by team
multi-aws list-team-accounts --team backend-team
# Clean up duplicate profiles
multi-aws clean-duplicates --dry-run
Configuration
The tool creates a configuration file at ~/.multi-aws/config.ini with comprehensive settings:
Configuration Sections
General Settings:
- AWS profile prefix for generated profiles
- SSO session name
- Default AWS region
- Account data file location
Output Settings:
- Filename pattern with placeholders (
!A=account-name,!c=command,!d=date) - Output format (json, yaml, txt, csv)
- Output directory path
Execution Settings:
- Execution mode (parallel or sequential)
- Error handling (stop after N errors)
- Command timeout settings
Security Settings:
- Allow/deny destructive commands
- Command validation rules
Logging Settings:
- Log level and file location
- Console logging preferences
- Log rotation settings
Environment Variables
You can override configuration using environment variables with the MULTI_AWS_ prefix:
export MULTI_AWS_REGION=eu-west-1
export MULTI_AWS_TIMEOUT=600
export MULTI_AWS_VERBOSE=1
Configuration File Example
[general]
prefix = multi-aws
sso-session = default
region = us-east-1
account-file = ~/.multi-aws/accounts.json
[output]
pattern = !A-!c-!d
format = json
path = ~/.multi-aws/outputs
[execution]
mode = sequential
stop-on-errors = 0
[security]
allow-destructive-commands = false
[logging]
level = INFO
file = ~/.multi-aws/logs/multi-aws.log
console = true
Using as a Python Library
MultiAWSTool can be imported and used as a library in other Python projects:
from multi_aws_tool import AccountManager, ConfigManager, OutputParser
# Initialize managers
config_manager = ConfigManager()
account_manager = AccountManager()
# Discover accounts
accounts = account_manager.discover_accounts()
# Parse execution results
from multi_aws_tool.output import parse_execution_summary
summary = parse_execution_summary('execution_summary_20251031_120000.json')
print(f"Success rate: {summary.success_rate:.1f}%")
For detailed library usage, see LIBRARY_USAGE.md and OUTPUT_MODULE.md.
Output Structure
MultiAWSTool generates structured output files that can be easily parsed by other tools:
Execution Summary Files
- Format:
execution_summary_YYYYMMDD_HHMMSS.json - Content: Complete execution results with metadata, timing, and error information
- Usage: Import using the
multi_aws_tool.outputmodule for analysis
Individual Account Output Files
- Format:
{account-name}-{command}-{date}.{format} - Content: Raw AWS CLI command output for each account
- Customizable: Filename patterns and formats configurable
Example Output Structure
~/.multi-aws/outputs/
├── execution_summary_20251031_120000.json
├── production-account-sts-get-caller-identity-20251031.json
├── staging-account-sts-get-caller-identity-20251031.json
└── dev-account-sts-get-caller-identity-20251031.json
Troubleshooting
Common Issues
Command not found after installation:
# Ensure the virtual environment is activated
source venv/bin/activate
# Or check if ~/.local/bin is in your PATH
export PATH="$HOME/.local/bin:$PATH"
SSO Authentication Failed:
# Check SSO configuration in ~/.aws/config
cat ~/.aws/config
# Re-initialize if needed
multi-aws init --sso-session your-session-name
Profile Generation Issues:
# Clean up existing profiles first
multi-aws clean-duplicates
# Regenerate profiles
multi-aws profiles --accounts <account-ids> --role <role-name> --append-to-config
Permission Errors:
# Check account roles
multi-aws roles --accounts <account-id>
# Verify profile works
aws --profile <profile-name> sts get-caller-identity
Debug Mode
Enable verbose logging for troubleshooting:
multi-aws --verbose <command>
Development
Setting up Development Environment
# Clone and setup
git clone <repository-url>
cd MultiAWSTool
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install in development mode
pip install -e .
# Install development dependencies
pip install -r requirements-dev.txt # if available
# Run tests
python -m pytest tests/ # if tests exist
Project Structure
MultiAWSTool/
├── multi_aws_tool/ # Main package
│ ├── __init__.py # Package exports
│ ├── main.py # CLI entry point
│ ├── output.py # Output parsing module
│ ├── aws/ # AWS integration
│ ├── cli/ # Command-line interface
│ ├── config/ # Configuration management
│ ├── models/ # Data models
│ └── utils/ # Utility functions
├── examples/ # Usage examples
├── pyproject.toml # Package configuration
├── requirements.txt # Dependencies
└── README.md # This file
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multi_aws_tool-0.1.1.tar.gz.
File metadata
- Download URL: multi_aws_tool-0.1.1.tar.gz
- Upload date:
- Size: 50.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ac8cf8e58fd23e82f23a7ddbca5928f6008107b79669b848c47fcc92ad0bc5f
|
|
| MD5 |
db1c17489978626760d3e65bb04b33ca
|
|
| BLAKE2b-256 |
86b54c9bc0c861940b14712a72584fadf9e706ce24200e0e724710a59561d88b
|
Provenance
The following attestation bundles were made for multi_aws_tool-0.1.1.tar.gz:
Publisher:
publish-pypi.yml on amahlaka/multi-aws-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multi_aws_tool-0.1.1.tar.gz -
Subject digest:
7ac8cf8e58fd23e82f23a7ddbca5928f6008107b79669b848c47fcc92ad0bc5f - Sigstore transparency entry: 1733103402
- Sigstore integration time:
-
Permalink:
amahlaka/multi-aws-tool@9eab40bdedff4fa9a319ad41fbb7e550ebb4a001 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/amahlaka
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9eab40bdedff4fa9a319ad41fbb7e550ebb4a001 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file multi_aws_tool-0.1.1-py3-none-any.whl.
File metadata
- Download URL: multi_aws_tool-0.1.1-py3-none-any.whl
- Upload date:
- Size: 56.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbca16477639554971cba2e935a3c8aeafeca39254eaa7dabf65b95f13ac74b8
|
|
| MD5 |
e9a933c8d59225707947b2ec0ee6ccfb
|
|
| BLAKE2b-256 |
4cb5b14e986f0360d27dbf08894275cd7dd36d8230092e846e046837f89a833f
|
Provenance
The following attestation bundles were made for multi_aws_tool-0.1.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on amahlaka/multi-aws-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multi_aws_tool-0.1.1-py3-none-any.whl -
Subject digest:
bbca16477639554971cba2e935a3c8aeafeca39254eaa7dabf65b95f13ac74b8 - Sigstore transparency entry: 1733103408
- Sigstore integration time:
-
Permalink:
amahlaka/multi-aws-tool@9eab40bdedff4fa9a319ad41fbb7e550ebb4a001 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/amahlaka
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9eab40bdedff4fa9a319ad41fbb7e550ebb4a001 -
Trigger Event:
workflow_dispatch
-
Statement type: