Allows you to read parameters from AWS Parameter Store and operate on results as on dictionary.
Project description
SSMEnv
master | develop | PyPI | Python | Licence |
---|---|---|---|---|
SSMEnv allows you to read parameters from AWS Parameter Store and operate on results as on dictionary.
Installation
You have to have boto3
installed then you can just run:
pip install ssmenv
Read parameters
Reading parameters is as simply as initialising class object.
from ssmenv import SSMEnv
ssmenv = SSMEnv(("/service/my-service", "/resource/dynamodb"))
# Accessing parameters
debug = ssmenv["SERVICE_MY_SERVICE_DEBUG"]
# As it's dictionary we can also:
# 1. Get list of all loaded parameter's names
list(ssmenv.keys())
# 2. Get list of all loaded parameter's values
list(ssmenv.values())
# and so on.
Populate 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")}
Remove 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
ssmenv = SSMEnv(("/service/my-service",), prefixes=("/service/my-service",))
ssmenv["DEBUG"]
Return 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_DEBUG"] = "1" # that might be set in docker-compose
ssmenv = SSMEnv(("/service/my-service",), no_aws_default=os.environ)
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.