aws_easy_mfa
aws_easy_mfa is a simple wrapper for AWS's boto3 that makes it much simpler to use with MFA.
Simply wrap any function invoking a boto3 session with the aws_easy_mfa decorator and you're off! aws_easy_mfa will take care of all the tedius MFA login steps.
Installation
You can install aws_easy_mfa via pip
pip install aws-easy-mfa
A simple example
Using boto3 to list bucket names in s3 with the aws_easy_mfa decorator.
from aws_easy_mfa import aws_easy_mfa
@aws_easy_mfa(mfa_device_arn='arn-of-the-mfa-device',
mfa_token_code='code-from-token')
def list_s3_buckets(session=None):
# Create an S3 client using the session
s3_client = session.client('s3')
# List all S3 buckets
response = s3_client.list_buckets()
# Extract the bucket names from the response
buckets = response['Buckets']
bucket_names = [bucket['Name'] for bucket in buckets]
return bucket_names
Optional arguments
You can control your MFA timeout by including duration_seconds as shown below
@aws_easy_mfa(mfa_device_arn='arn-of-the-mfa-device',
mfa_token_code='code-from-token',
duration_seconds=3600)
def list_s3_buckets(session=None):
...
In addition, if you would like your MFA-authorized sesssion for further usage, you can add the return_session=True flag to your decorator, like this
@aws_easy_mfa(mfa_device_arn='arn-of-the-mfa-device',
mfa_token_code='code-from-token',
duration_seconds=3600,
return_session=True)
def list_s3_buckets(session=None):
...
The session is returned as a second argument. So for example instead of
bucket_names = list_s3_buckets()
enabling this flag returns your session as
bucket_names, session = list_s3_buckets()
Direct session retrieval
You can also create an MFA session without usage of the decorator as shown below:
from aws_easy_mfa.utilities import get_mfa_credentials, create_boto3_session
# get credentials
credentials = get_mfa_credentials(mfa_device_arn='arn-of-the-mfa-device',
mfa_token_code='code-from-token',
duration_seconds)
# generate mfa-authorized session
session = create_boto3_session(credentials)
Metadata
Release files for aws-easy-mfa 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aws_easy_mfa-0.1.1.tar.gz | 2.3 kB | Without provenance | Details for aws_easy_mfa-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aws_easy_mfa-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for aws_easy_mfa-0.1.1-py3-none-any.whl |
Total release size: 5.4 kB
Release files / aws_easy_mfa-0.1.1.tar.gz
| Download URL | aws_easy_mfa-0.1.1.tar.gz |
|---|---|
| Size | 2.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd6f02394396f3e47100545797104ff923d8eb30232a26fcc3b1420871c9c3d9
|
|
BLAKE2b-256 checksum How to use checksums |
46b79df7dfb329535176e0f2b8bc60bd08fcc277766c9c3211d8f33055156e87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / aws_easy_mfa-0.1.1-py3-none-any.whl
| Download URL | aws_easy_mfa-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01e0acac575a6d2692e3c46f9d0adbe72badf91c9b59585f8faf548a9e015e64
|
|
BLAKE2b-256 checksum How to use checksums |
b21fc5fcf18db77f9d8b13680643249723a1691d1763e43cd75a9157063246db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for aws-easy-mfa 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.