SSMEnv
| master | coverage | PyPI | Python | Licence |
|---|---|---|---|---|
SSMEnv allows you to read parameters from AWS Parameter Store and operate on results as on dictionary.
Installation
Only requirement is to have boto3 installed.
pip install ssmenv
Reading parameters
Let's assume we have two parameters token and url under /service/my-service namespace.
Reading both parameters is as simple as initialising class object.
from ssmenv import SSMEnv
params = SSMEnv("/service/my-service")
Done! Now we can access /service/my-service/token and /service/my-service/url in params variable!
Now params can be accesses as python dict type.
Interacting with SSMEnv instance
As you know by now, instance of SSMEnv can be accessed as any dict in python which means you can do things like:
from ssmenv import SSMEnv
params = SSMEnv("/service/my-service")
# 1. Access value directly
token = params["SERVICE_MY_SERVICE_TOKEN"]
# 2. Get list of all loaded parameter's names
list(params.keys())
# 3. Get list of all loaded parameter's values
list(params.values())
# and so on...
Fetching multiple namespaces at once
In real world most often you will access parameters from different namespaces, you can easily do that with SSMEnv
by passing tuple
from ssmenv import SSMEnv
params = SSMEnv("/service/my-service", "/resource/mysql")
Now params will have all parameters from both /service/my-service and /resource/mysql.
AWS Lambda decorator
If you use AWS lambda, you might find handy ssmenv decorator. It behaves same as if you would initialise SSMEnv by hand, but additionally it injects instance of SSMEnv into context.params attribute.
from ssmenv import ssmenv
@ssmenv("/service/my-service")
def handler(event, context):
return context.params
Populating os.environ
You can hide use of SSMEnv by using os.environ dict.
import os
from ssmenv import SSMEnv
os.environ = {**os.environ, **SSMEnv("/service/my-service")}
Removing common prefixes
Accessing your parameters through whole namespaces can sometimes be not convenient especially if you have very long names.
Hence why you can use prefixes parameter, to make your code cleaner.
from ssmenv import SSMEnv
params = SSMEnv("/service/my-service", prefixes=("/service/my-service",))
params["TOKEN"]
Returning dict in case there is no AWS context
You might want to run your application without AWS, e.g. through docker on your local machine and mock parameters.
For that you can use no_aws_default attribute.
import os
from ssmenv import SSMEnv
os.environ["SERVICE_MY_SERVICE_TOKEN"] = "mocked-token" # that might be set in docker-compose
params = SSMEnv("/service/my-service", no_aws_default=os.environ)
Passing your own boto3 client
You can pass your own boto3 client as well.
import boto3
from ssmenv import SSMEnv
ssm_client = boto3.client("ssm")
params = SSMEnv("/service/my-service", ssm_client=ssm_client)
Metadata
Release files for ssmenv 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ssmenv-2.1.0.tar.gz | 4.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ssmenv-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / ssmenv-2.1.0.tar.gz
| Download URL | ssmenv-2.1.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80504922c5824ce44093645f3e915493e0e8d20dd3173447d57fea2af1b525f8
|
|
BLAKE2b-256 checksum How to use checksums |
c35a158299522ed97768dac1eac964e56d7537dd65c05becd23f5a70ac8ceb8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0a2 CPython/3.6.5 Darwin/19.0.0
|
Release files / ssmenv-2.1.0-py3-none-any.whl
| Download URL | ssmenv-2.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9fd343f31ab8e7ec408179dfebcb948141bdf20332b9ea0ce821cb486fec2c00
|
|
BLAKE2b-256 checksum How to use checksums |
e1984ccb28aac0310c3e608abfe8a01d5e6df2063e67dff2cba178433bad5858
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.0a2 CPython/3.6.5 Darwin/19.0.0
|
Security for ssmenv 2.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.