Skip to main content

A simple configuration variable wrapper around AWS SSM Parameter Store

Project description

ps-environ

Description

This is a simple wrapper around AWS SSM Parameter Store. It is designed to cache and parse variables from Parameter Store for a specific service and stage. It is heavily inspired by django-environ and shares a (simplified) interface.

For more on Parameter Store, read the AWS documentation.

Installation

Install with pip:

pip install parameter-store-environ 

Usage

The wrapper assumes that variables in parameter store are in the following format: /<SERVICE>/<STAGE>/<VARIABLE_NAME>

So, for example:

/api/dev/DEBUG
/api/prod/DB_HOST

The wrapper is agnostic to the variable name, but we recommend you follow the convention for environment variables and use all caps and underscores.

In your settings/configuration module, import the module and create a new instance of the wrapper

from ps_environ import Env
config = Env(service='api', stage='dev')

# When called directly, the string value is returned
assert config('DEBUG') == 'True'

# Use casting methods to return the type you need
assert config.bool('DEBUG') == True

Schemas

You can define a schema when you instantiate the wrapper to avoid having to call the casting methods

config = Env(service='api', stage='dev', schema={
    'DEBUG': bool,
    'MAX_RETRIES': int,
})

assert config('DEBUG') == True
assert config('MAX_RETRIES') == 5

Supported casting types: bool, float, int, set, list, tuple, json

Additional Notes:

  • list, tuple, set: These types expect the values to be separated by commas. E.g. 1,2,3
  • json: A regular JSON string is expected. E.g. {'foo': 'bar'}

Environment Variable Override

If the variable is also set in the environment, that value will take precedence.

Default Values

You can set a default value by setting the default keyword. If no default is set and the value is neither in the environment variables or in parameter store, an ImproperlyConfigured exception will be raised.

assert config('DB_HOST', default='localhost') == 'localhost'

AWS Credentials

ps-environ uses boto3 to interface with parameter store and therefore uses the same mechanism for authentication. See the configuring credentials in the Boto 3 documentation for more information.

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

parameter-store-environ-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parameter_store_environ-0.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file parameter-store-environ-0.1.2.tar.gz.

File metadata

  • Download URL: parameter-store-environ-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for parameter-store-environ-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eae9d193303f0f9ffa2f534b1625061ec0266d426076c9557d4843b44aef04b3
MD5 f3871ef2bd3fc885629040ece741c164
BLAKE2b-256 a80d117fc878b15be937ba54b09db5eca442c4d74e48bb19e2bc43ecfeb60ca5

See more details on using hashes here.

File details

Details for the file parameter_store_environ-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: parameter_store_environ-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for parameter_store_environ-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6d50a9b54e759a4744ab082c49b6cd8f5db4ad6de094df547394ea3d195e1a10
MD5 4dc886bdc2724d1965e70c3b22d30e73
BLAKE2b-256 73a632145eaccad310dd7603e2220c30fa8b49654d94002dc10e9d119759ecb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page