Skip to main content

Execute AWS CLI across multiple profiles and multiple regions in one go

Project description

Avatar

Build Status Code Scanning Status Dependencies Status Security Status Published Version

mpaws

mpaws is a Python CLI for running an AWS command across multiple profiles and multiple regions in one go.

This is a time-saver when you are managing dozens of AWS accounts and need to run the same command across all of them.

Installation

pip3 install mpaws

Usage

Set an environment variable MPAWS_PROFILES, and another environment variable MPAWS_REGIONS, then run mpaws command:

export MPAWS_PROFILES=profile1,profile2,profile3
export MPAWS_REGIONS=us-east-1,ap-southeast-2
mpaws ec2 describe-instances

The above command will run aws ec2 describe-instances command for each permutation of the AWS profiles and AWS regions, like these:

AWS_PROFILE=profile1 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances
AWS_PROFILE=profile1 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 aws ec2 describe-instances
AWS_PROFILE=profile2 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances
AWS_PROFILE=profile2 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 aws ec2 describe-instances
AWS_PROFILE=profile3 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances
AWS_PROFILE=profile3 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 aws ec2 describe-instances

Alternatively, you can also run mpaws with multiple AWS profiles against a single AWS region. You can do this by setting the environment variable MPAWS_PROFILES, then run mpaws command:

export MPAWS_PROFILES=profile1,profile2,profile3
mpaws ec2 describe-instances

The above command will run aws ec2 describe-instances command using each AWS profile, combined with the configured AWS region (either via AWS_DEFAULT_REGION, AWS_REGION, or the configured region within the profile definition).

Here's an example if AWS_DEFAULT_REGION is specified with us-east-1 as the value:

AWS_PROFILE=profile1 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances
AWS_PROFILE=profile2 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances-instances
AWS_PROFILE=profile3 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 aws ec2 describe-instances

Note that each run will also carry over the environment variables available from the original mpaws command run.

Custom command

If you need to run a custom command using each profile, you can use the _ (underscore) character which will tell mpaws to run the custom command AS-IS.

Here's an example:

export MPAWS_PROFILES=profile1,profile2,profile3
export MPAWS_REGIONS=us-east-1,ap-southeast-2
mpaws _ echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}

Which will run the custom command against the permutation of the AWS profiles and AWS regions:

AWS_PROFILE=profile1 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}
AWS_PROFILE=profile1 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}
AWS_PROFILE=profile2 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}
AWS_PROFILE=profile2 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}
AWS_PROFILE=profile3 AWS_DEFAULT_REGION=us-east-1 AWS_REGION=us-east-1 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}
AWS_PROFILE=profile3 AWS_DEFAULT_REGION=ap-southeast-2 AWS_REGION=ap-southeast-2 echo \$\{AWS_PROFILE\} \$\{AWS_REGION\}

Configuration

Ensure that the profiles specified in MPAWS_PROFILES are already configured in credential file. And the regions specified in MPAWS_REGIONS, AWS_DEFAULT_REGION, AWS_REGION, or AWS configuration are valid regions.

Environment Variable Mandatory Example
MPAWS_PROFILES Yes profile1,profile2,profile3
MPAWS_REGIONS No us-east-1,ap-southeast-2
AWS_DEFAULT_REGION No us-east-1
AWS_REGION No us-east-1

Colophon

Developer's Guide

Build reports:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpaws-1.0.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpaws-1.0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file mpaws-1.0.2.tar.gz.

File metadata

  • Download URL: mpaws-1.0.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

File hashes

Hashes for mpaws-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8f41195c98e4ddd3981122aaacd6f95f046a774b43542939583ddfdba9d03a85
MD5 e1ceb32a687a3c657de308ee6dfc06ca
BLAKE2b-256 e73dba7e8ae13158bfc35657d8d1b1340aae46f1c69932f3718b357c9adbfaac

See more details on using hashes here.

File details

Details for the file mpaws-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mpaws-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

File hashes

Hashes for mpaws-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e37324dbd2124c2aed21e79c2632bdf29aa75cc7f57bd1162108d2634a92511
MD5 81ec2c7c2e348b07711acc65d58cac65
BLAKE2b-256 31fbd172c8f9681bbed3cd9e051ec932f4691e6bf669a93b5c4834cf9a6949f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page