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.s3_client
One click to jump to the documentation:
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
Hashes for boto_session_manager-1.3.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409eaaf0f0e7ff4adbcbcb3871e273f6a3ba081e044bb2ab5e8260f59db97042 |
|
MD5 | cb31698837fa042538bc3fbea407114d |
|
BLAKE2b-256 | 4b7495c1325e2a205789dc83d37c649ba92b4a2c23861615b798e02486c948d6 |
Hashes for boto_session_manager-1.3.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ab9b2b20b8797c50c183eb2b955467250ea972faab18e56c7efef9b70bf2424 |
|
MD5 | b0f596f3fbc3d968abf75ad9ba4ac8c8 |
|
BLAKE2b-256 | 713ccd69ebf9798b8cdbe45327820888f3db9646d5db8804c57fc44b4a92666d |