Skip to main content

AWS Profile Switcher Readme

Overview

The script is a handy tool to help AWS users switch between different AWS CLI profiles quickly. This can be particularly useful if you manage multiple AWS accounts or if you have different roles within an AWS account. After you've switched profiles, the script allows you to set the AWS profile in your environment variables or retrieve user details for that profile.

Features:

  1. List AWS CLI Profiles: Displays a list of AWS CLI profiles stored in ~/.aws/credentials.
  2. Switch Profile Interactively: Allows the user to select an AWS profile from a list.
  3. Set Environment Variable: Once a profile is chosen, the script will generate a command to set the AWS_PROFILE environment variable in the user's shell. This command is copied to the clipboard for easy pasting.
  4. Display User Details: Once a profile is chosen, the script displays the User ID, ARN, Access Key, and Secret Key for the selected profile.

Instructions

  1. Running without parameters will directly output the default configured identity information:
awsx
  1. Using the --profile flag, the tool will prompt you to select an AWS CLI profile. If you already know the profile name you want to use, you can pass it as the profilename parameter:
awsx --profile

or

awsx --profile your_profilename
  1. Use the --region flag to specify the AWS region:
awsx --region us-west-1

Detailed code explanation

Here is a brief explanation of some code snippets:

  • get_identity(): Get AWS identity information.
  • get_parent_process_name(): Gets the name of the parent process, which is used to determine whether it is running in powershell or cmd.
  • copy_env_command_to_clipboard(): Based on the operating system and process name, generate a command to set the AWS_PROFILE environment variable and copy it to the clipboard.
  • list_aws_profiles(): List all AWS CLI profiles.
  • get_region_from_profile(): Get the default region from the given AWS CLI profile.
  • switch_aws_profile_interactive(): Interactively prompts the user to select an AWS CLI profile and returns its name and default region.

The tool uses the click library to parse command line arguments, the boto3 library to interact with AWS, the pyperclip library to copy text to the clipboard, and several other libraries to obtain system information and read configuration document.

Features:

  1. List AWS CLI Profiles: Displays a list of AWS CLI profiles stored in ~/.aws/credentials.
  2. Switch Profile Interactively: Allows the user to select an AWS profile from a list.
  3. Set Environment Variable: Once a profile is chosen, the script will generate a command to set the AWS_PROFILE environment variable in the user's shell. This command is copied to the clipboard for easy pasting.
  4. Display User Details: Once a profile is chosen, the script displays the User ID, ARN, Access Key, and Secret Key for the selected profile.

Notes:

  • The script determines the user's operating system to generate the appropriate command to set environment variables. It supports Windows (both cmd and PowerShell), Linux, and macOS.
  • If there's an issue connecting to the specified region, the script defaults to connecting to the "us-east-1" region.

Recommendations:

  • Always be cautious about where and how you display AWS Access and Secret keys. Avoid logging these details or exposing them to unintended audiences.
  • It's advisable to have a backup of your AWS CLI configuration files (~/.aws/credentials and ~/.aws/config) before using any scripts or tools that modify or interact with them.

Feedback and Contributions:

Please raise any issues or suggestions on the repository or contact the maintainers directly. Contributions to enhance the script or fix any bugs are always welcome!

Metadata

Release files for awsx 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awsx 2.0.0
File Size Uploaded
awsx-2.0.0.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for awsx 2.0.0
File Interpreter ABI Platform
awsx-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / awsx-2.0.0.tar.gz

Download URL awsx-2.0.0.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cd1995559b9b27b7b07f744161b959ff0db6d2d65ee8e68c3d1700fb28619222
BLAKE2b-256 checksum
How to use checksums
72559f657b026f9e9663098747ee367a62ae3c2b649a04546446deb637ffadd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / awsx-2.0.0-py3-none-any.whl

Download URL awsx-2.0.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a166a135f47eee59e1f0828768f044cefca5ab0e13da6323536e43c231274a01
BLAKE2b-256 checksum
How to use checksums
667f896f6550d620e9df0f969cf961074737c8e2c53cefb4b23dc594ac7ea4ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page