Python package that interfaces with AWS System Manager
Project description
python-aws-ssm
Python package that interfaces with AWS System Manager.
Why to use python-aws-ssm and not the boto3 SSM client?
This package is wrapping boto3 SSM client and hides the complexity dealing with the not so Python friendly AWS SDK. Perfect use case for this package is when secure parameters for an application are stored to AWS Parameter Store using a path hierarchy. During application startup you can use this package to fetch them and use them in your application.
Warning
The SSM service is rate-limited by default. We strongly suggest using
retrieving SSM keys by path, e.g. via ParameterStore.get_parameters_by_path()
.
This requires grouping keys by a useful path but reduces the chance of
your own services being rate-limited in turn.
Install
pip install aws-ssm
Examples
Basic Usage
from aws_ssm.parameters import ParameterStore
# Assuming you have the parameters in the following format:
# my-service/dev/param-1 -> with value `a`
# my-service/dev/param-2 -> with value `b`
parameter_store = ParameterStore()
# Requesting the base path
parameters = parameter_store.get_parameters_by_path("/my-service/dev/")
# And getting a specific value
value = parameters.get("param-1")
# value should be `a`
Recursive and nested options
from aws_ssm.parameters import ParameterStore
# Assuming you have the parameters in the following format:
# my-service/dev/param-1 -> with value `a`
# my-service/dev/param-2 -> with value `b`
parameter_store = ParameterStore()
# Requesting the base path
parameters = parameter_store.get_parameters_by_path(
"/my-service/", recursive=True, nested=True
)
# And getting a specific value
dev_parameters = parameters.get("dev")
# value should be {"param-1": "a", "param-2": "b"}
Get parameters by name
from aws_ssm.parameters import ParameterStore
# Assuming you have the parameters in the following format:
# my-service/dev/param-1 -> with value `a`
# common/dev/param-2 -> with value `b`
parameter_store = ParameterStore()
# Requesting the base path
parameters = parameter_store.get_parameters(
["/my-service/dev/param-1", "/common/dev/param-2"]
)
# And getting a specific value
dev_parameters = parameters.get("/common/dev/param-2")
# value should be `b`
With custom client
from aws_ssm.parameters import ParameterStore
import boto3
# Initialise an SSM client to specify the source of the credentials.
# e.g. locally a profile would be more likely; an AWS Lambda would most
# likely not override the credentials source.
ssm_client = boto3.Session(profile_name='dev').client('ssm')
parameter_store = ParameterStore(ssm_client)
parameters = parameter_store.get_parameters(["/service/path/"])
Development
If you are missing any features or have found a bug, please open a PR or a new Github issue.
Setup
This project uses Poetry to manage the dependencies and the virtual environment. Follow the instructions from Poetry website (https://poetry.eustace.io/docs/#installation) to configure your local environment.
After completing the Poetry setup, the virtual environment can be created running:
make setup
Tests
Tests are run by Pytest
make test
Code style
- Mypy is used for type annotations (https://github.com/python/mypy)
- Black formatter (https://github.com/psf/black) is used to keep the coding style consistent.
- Isort (https://github.com/timothycrosley/isort) is used to sort the imports. To format the codebase just run:
make format
and to check it before pushing:
make lint
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 python_aws_ssm-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 541259e350fe950ff31f104fcc714da795b7bdce5cad0599f181d2761e8395bb |
|
MD5 | 1c9e9264024911b1979d0c68f745d803 |
|
BLAKE2b-256 | cecb93614764fb1b2642ac52bdf2bddd3c19a86681cba2178190223f69e22e0a |