Utility for extracting Boto3 configuration information and method parameters from AWS resource URIs.
Project description
Boto3 URI utility library that supports extraction of Boto3 configuration data and method parameters from AWS resource URIs.
Purpose
When applications that employ Boto3 must work with AWS resources that are spread across multiple accounts, it can be useful to tie AWS configuration information (both credentials and non-credentials) directly to associated AWS resources (e.g., by including the configuration data within URIs). This library provides a class that extracts AWS configuration data and method parameters from a URI, offering a succinct syntax for passing (directly into Boto3 methods) configuration data and/or resource names that are included within URIs.
Package Installation and Usage
The package is available on PyPI:
python -m pip install b3u
The b3u class can be imported with:
from b3u import b3u
Examples
The class provides methods for extracting configuration data (credentials and non-credentials) from URIs. The example below illustrates the creation of an S3 client object from a given a URI (for an S3 bucket), where the URI includes credentials (an access key ABC, a secret key XYZ, and a session token UVW):
>>> import boto3 >>> from b3u import b3u >>> b = b3u("s3://ABC:XYZ:UVW@example-bucket") >>> boto3.client('s3', **b.cred())
The example below creates an S3 client given a URI (for an object in an S3 bucket) where the URI includes credentials (an access key ABC and a secret key XYZ). The same URI is then used to retrieve a handle for the object itself:
>>> b = b3u("s3://ABC:XYZ@example-bucket/object.data") >>> c = boto3.client(**b.for_client()) >>> o = c.get_object(**b.for_get())
The example below creates an SSM client given a URI (naming a particular a parameter in the Parameter Store) that specifies the AWS Region us-east-1:
>>> b = b3u("ssm://ABC:XYZ@/path/to/parameter?region_name=us-east-1") >>> boto3.client('ssm', **b.conf())
The example below creates an SSM client given a URI that contains no credentials but does specify an AWS Region. Since no credentials are present in the URI, the Boto3 Python library will look for them in other locations in the manner specified in the Boto3 documentation):
>>> b = b3u("ssm:///path/to/parameter?region_name=us-east-1") >>> boto3.client('ssm', **b.conf())
Developer Notes
Pipenv is used for dependency management of the main library, minus Read the Docs which does not support Pipenv. You can install all dependencies with:
pipenv install --dev
To release a new version of the library, run:
pipenv run python -m pip install --upgrade build twine pipenv run python -m build pipenv run twine upload dist/*
Documentation
The documentation can be generated automatically from the source files using Sphinx:
python -m pip install -e . cd docs python -m pip install -r requirements.txt sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
Testing and Conventions
All unit tests are executed and their coverage is measured when using pytest (see setup.cfg for configuration details):
pipenv run python -m pytest --cov=b3u --cov-report term-missing
Alternatively, all unit tests are included in the module itself and can be executed using doctest:
pipenv run python src/b3u/b3u.py -v
Style conventions are enforced using Flake8:
pipenv run python -m flake8 src/ tests/
Contributions
In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.
Versioning
The version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.
MIT License
Copyright (c) 2021 Nth Party, Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
Built Distribution
File details
Details for the file b3u-2.0.0.tar.gz
.
File metadata
- Download URL: b3u-2.0.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef85193337de2dd3b6021164ca56f54eb2cb80e3cb77d27abc7415fdc3f2ac3 |
|
MD5 | 2032102fcebee2aa5b6ec99be84a7a72 |
|
BLAKE2b-256 | b3da7535eb6a9f57730c2619cf22d5143f294045641a3b4d51ad4c07a6430d70 |
File details
Details for the file b3u-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: b3u-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7072bf002005afca79e449e8a2ea3ee7eb0d930eb207122c459fb608a18503 |
|
MD5 | 644ffc66917bd8dcf547223342584969 |
|
BLAKE2b-256 | c5051d161816cf35d5c101475ad5ab2aa4bfda1c7a0c4b76793890f4a12eaa74 |