Python AWS SDK boto3 library enhancement
Project description
Welcome to boto_session_manager Documentation
Feature
Boto Client Enum
Provide an Enum class to access the aws service name to create boto client.
from boto_session_manager import BotoSesManager, AwsServiceEnum
bsm = BotoSesManager()
s3_client = bsm.get_client(AwsServiceEnum.S3)
Cached Client
Once an boto session is defined, each AWS Service client should be created only once in most of the case. boto_session_manager.BotoSesManager.get_client(service_name) allow you to fetch the client object from cache if possible.
from boto_session_manager import BotoSesManager, AwsServiceEnum
bsm = BotoSesManager()
s3_client1 = bsm.get_client(AwsServiceEnum.S3)
s3_client2 = bsm.get_client(AwsServiceEnum.S3)
assert id(s3_client1) = id(s3_client2)
Or you can just do:
bsm.s3_client.list_buckets() # it cache the client when needed
Assume Role
Create another boto session manager based on an assumed IAM role. Allow you to check if it is expired and maybe renew later.
bsm_assumed = bsm.assume_role("arn:aws:iam::669508176277:role/sanhe-assume-role-for-iam-test")
sts_client = bsm_assumed.get_client(AwsServiceEnum.sts)
print(sts_client.get_caller_identity())
print(bsm_assumed.is_expired())
AWS CLI context manager
Suppose you have a boto session manager defined in python, sometime you want to run aws cli from Python using subprocess library. You can use boto_session_manager.BotoSesManager.awscli() context manager to setup temp credential for AWS CLI.
import subprocess
bsm = BotoSesManager(...)
with bsm.awscli():
subprocess.run(["aws", "sts", "get-caller-identity"])
Install
boto_session_manager is released on PyPI, so all you need is:
$ pip install boto_session_manager
To upgrade to latest version:
$ pip install --upgrade boto_session_manager
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 boto_session_manager-1.3.1.tar.gz.
File metadata
- Download URL: boto_session_manager-1.3.1.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7db3aad3478fad5b6e307660880790df4ffdc8c417057c1594d7c68dc779ce40
|
|
| MD5 |
31f47a4662bbd9a7d531ba8f6b958c48
|
|
| BLAKE2b-256 |
4028936b22f53e48f1b50c700c9aa7ba8d7deb7e611e14232442e3f87997c874
|
File details
Details for the file boto_session_manager-1.3.1-py2.py3-none-any.whl.
File metadata
- Download URL: boto_session_manager-1.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12d99b72d3c8dd7df5a919a45f2f77b085484aacea0424e37b13f5a3ab2e258d
|
|
| MD5 |
1a50dac897173b8704831e729fc93289
|
|
| BLAKE2b-256 |
b85ac058cf66de50713a92e2f480325cc9246806484063a1d3aa4c4600615170
|