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.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)

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.2.2.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boto_session_manager-1.2.2-py2.py3-none-any.whl (22.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file boto_session_manager-1.2.2.tar.gz.

File metadata

  • Download URL: boto_session_manager-1.2.2.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.11

File hashes

Hashes for boto_session_manager-1.2.2.tar.gz
Algorithm Hash digest
SHA256 b0df421b8b9e43c23ee626cd912b0e69cfbd50c4d26b46bda58811bf1016719c
MD5 6596ca6de4020097b5a07896e2dded1e
BLAKE2b-256 5a4f0af6eac43125e5ef2a7578fe672b58d448e325cce421cbcf67acd9a25044

See more details on using hashes here.

File details

Details for the file boto_session_manager-1.2.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for boto_session_manager-1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 06e8dc9ef4f7b1dfb206f1b59d5578aaa02a5c1e91edd315515fa8c176114dcd
MD5 f1f256d7a64b741edf9ac012226dfc81
BLAKE2b-256 5f3e7088309787889dcaea886e08622fd5781dd04c024f8dca5b35e038893b6c

See more details on using hashes here.

Supported by

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