A CLI tool to manage AWS MFA session tokens easily.
Project description
AWS MFA Helper CLI
aws-mfa-helper-cli
is a simple command-line tool that helps manage AWS MFA session tokens. It automates the process of generating a session token using MFA and stores the credentials in a separate session profile, allowing you to easily switch between your original and session profiles.
Prerequisites
Before using this package, make sure you have set up your AWS credentials in ~/.aws/credentials
. The credentials file should contain your AWS access key ID and secret access key for the profiles you want to use MFA with.
Here's an example of the AWS credentials file (~/.aws/credentials
):
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
Installation
You can install this package using pip:
pip install aws-mfa-helper-cli
Usage
Setting Up IAM Account and Device (Optional)
Before generating an MFA session token, you can configure your IAM account ID and MFA device for a specific profile to avoid entering them every time. You can do this by running the following command:
aws-mfa-helper-cli --config --profile your-profile-name --iam-account-id 123456789012 --device your-mfa-device
Example:
aws-mfa-helper-cli --config --profile your-profile --iam-account-id 123456789012 --device iphone
This will save the IAM account ID and device name for the specified profile. The next time you use this profile, the tool will automatically use these values.
Generating a New Session Token
To generate an MFA session token, run the following command:
aws-mfa-helper-cli --profile your-profile-name --token-code 123456
Example:
aws-mfa-helper-cli --profile your-profile --token-code 654321
The tool will use the specified profile to generate a session token using your MFA device. The session token credentials will be stored in a new profile named <profile-name>-session
.
Using the Session Profile
Once the session token is generated, you must use the session profile for all your subsequent AWS commands during the session period. The session profile will be named <profile-name>-session
. For example, if you generated the session token for the profile your-profile
, you can now use the profile your-profile-session
for your AWS commands:
aws s3 ls --profile your-profile-session
The session credentials will expire after a period (usually 12 hours), after which you will need to run the aws-mfa-helper-cli
command again to get a new session token.
Handling the Region
If your original profile has a region specified in the ~/.aws/config
file, the region will automatically be copied over to the session profile. If not, the AWS CLI will use the default region.
Example Workflow
-
Set up your IAM account ID and device for a profile (Optional but recommended):
aws-mfa-helper-cli --config --profile your-profile --iam-account-id 123456789012 --device iphone
-
Generate a session token:
aws-mfa-helper-cli --profile your-profile --token-code 654321
This will create a session profile named
your-profile-session
. -
Use the session profile for AWS commands:
aws s3 ls --profile your-profile-session
Notes
- The
aws-mfa-helper-cli
tool will create a new session profile every time you run the command. You must use this session profile for all AWS operations while the session is active. - If your session credentials expire, simply run the
aws-mfa-helper-cli
command again to generate a new session token.
License
This project is licensed under the 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
File details
Details for the file aws_mfa_helper_cli-0.1.0.tar.gz
.
File metadata
- Download URL: aws_mfa_helper_cli-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e93a89f24a73810eb6797e13176d865bdc55e53e789ecaa67a2d22d41a6198ac |
|
MD5 | 3cee6817ab825823caf0b8571804d07e |
|
BLAKE2b-256 | 9f52caab800e2b7ec93e6772f5e5ecf3be9a3f0ffa30890d215d111ce93dcb12 |
File details
Details for the file aws_mfa_helper_cli-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: aws_mfa_helper_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4c90836444a1bb78405ba523ad5725bed5e0856f413b69cb780641944c0d879 |
|
MD5 | 8bd7dcfe152483414177dfe9449b4440 |
|
BLAKE2b-256 | 98cbfbffd80ad79cd31fa87b91aea8a7063b9bf6c2c323d487468bb0bbee7b69 |