Load parameters from AWS Parameter Store
Project description
AWStanding
Easily load variables from AWS Parameter store into environment variables.
Why to AWStanding?
Because it handles AWS pagination so the amount of requests performed to retrieve the parameters are the bare minimum. Also it handles invalid parameters, so you don't have to deal with undefined variables exceptions, as an option.
Quickstart
from awstanding.parameter_store import load_parameters
load_parameters({'/some/path/to/something/stored': 'IMPORTANT_SETTING'})
import os
print(os.environ.get('IMPORTANT_SETTING'))
'super-important-value'
Using with python-decouple
import os
from awstanding.parameter_store import load_parameters
from decouple import config
load_parameters({'/some/path/to/something/stored': 'IMPORTANT_SETTING'})
IMPORTANT_SETTING = config('IMPORTANT_SETTING', default='some-default')
print(IMPORTANT_SETTING)
'super-important-value'
Not allowing missing parameters
from awstanding.parameter_store import load_parameters
# A call like this one:
load_parameters({'/not/defined/parameter': 'IMPORTANT_SETTING'}, allow_invalid=False)
# will raise a ParameterNotFoundException, and you can handle it as follows:
from awstanding.exceptions import ParameterNotFoundException
try:
load_parameters({'/not/defined/parameter': 'IMPORTANT_SETTING'}, allow_invalid=False)
except ParameterNotFoundException as e:
# perform any cleanup action..
Performance
Amount of parameters | Missing parameters | AWStanding | SSM client calls |
---|---|---|---|
40 | 0 | ~3.1s | ~15.5s |
40 | 0 | ~2.4s | ~15.3s |
40 | 0 | ~4.6s | ~14.5s |
40 | 0 | ~2.5s | ~15.5s |
40 | 1 | ~2.1s | error: ParameterNotFound |
40 | 20 | ~2.2s | error: ParameterNotFound |
40 | 40 | ~2.1s | error: ParameterNotFound |
80 | 40 | ~3.5s | error: ParameterNotFound |
80 | 40 | ~3.9s | (using try..except) ~32.7s |
Loading paths
Suppose you have defined these variables in ParameterStore:
'/stripe/price/'
'/stripe/webhook/' # (Let's not define this one just for demonstration)
You can leverage on the good naming and perform a path variable loading as follows:
import os
from awstanding.parameter_store import load_path
load_path('/stripe', '/spotify')
STRIPE_PRICE = os.environ.get('STRIPE_PRICE', 'fallback_value')
STRIPE_WEBHOOK = os.environ.get('STRIPE_WEBHOOK', 'fallback_value')
SPOTIFY_API_KEY = os.environ.get('SPOTIFY_API_KEY', 'fallback_value')
print(f'price: {STRIPE_PRICE}, webhook: {STRIPE_WEBHOOK}, spotify: {SPOTIFY_API_KEY}')
>>> price: price_1xxxxxxxxxxxxxxxxxxxxxxx, webhook: fallback_value, spotify: fallback_value
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
awstanding-1.0.4.tar.gz
(15.7 kB
view hashes)
Built Distribution
awstanding-1.0.4-py3-none-any.whl
(16.1 kB
view hashes)
Close
Hashes for awstanding-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f12c6fee3639bb886420a63c09545f0e404f69e332c6875ee531aaccfaec5d33 |
|
MD5 | a5b55d26fd5f2c0e20124a163401dcbe |
|
BLAKE2b-256 | df5fd5040b0340c5e45fb9a208d079fc9ddddfabdddbdc221e460651e42cc24f |