Skip to main content

Python AWS SDK boto3 library enhancement

Project description

https://github.com/MacHu-GWU/boto_session_manager-project/workflows/CI/badge.svg https://codecov.io/gh/MacHu-GWU/boto_session_manager-project/branch/main/graph/badge.svg https://img.shields.io/pypi/v/boto_session_manager.svg https://img.shields.io/pypi/l/boto_session_manager.svg https://img.shields.io/pypi/pyversions/boto_session_manager.svg https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social
https://img.shields.io/badge/Link-Install-blue.svg https://img.shields.io/badge/Link-GitHub-blue.svg https://img.shields.io/badge/Link-Submit_Issue-blue.svg https://img.shields.io/badge/Link-Request_Feature-blue.svg https://img.shields.io/badge/Link-Download-blue.svg

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
https://user-images.githubusercontent.com/6800411/215315251-162886ee-067e-4441-882e-f2641b0997ca.gif

One click to jump to the documentation:

https://user-images.githubusercontent.com/6800411/215315252-52d89d6a-d234-4635-b412-044894a46442.gif

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boto_session_manager-1.3.2.tar.gz (45.8 kB view hashes)

Uploaded Source

Built Distribution

boto_session_manager-1.3.2-py2.py3-none-any.whl (43.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page