Skip to main content

AWStanding

Easily load variables from AWS Parameter store into environment variables.

Why to use AWStanding?

Despite it's built on top of Boto3, it has the following key features that eases the development process:

  • Simpler API
  • Error Handling
  • Pagination handling when needed (Saves you a buch of boilerplate)
  • Dynamic Parameters (variables that listen to updates on AWS)
  • S3 Integration made easy with Download/Upload methods

Installation

pip install awstanding

I personally recommend using pipenv:

pipenv install awstanding

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

Dynamic Parameters

You can define dynamic parameters that uploads themselves each time they are used, so you can update any parameter without re-deploy your service.

from awstanding.parameter_store import DynamicParameter

IMPORTANT_SETTING = DynamicParameter('/test/parameter')

print(IMPORTANT_SETTING)
>>> OriginalValue

# Someone updates /test/parameter on AWS...

print(IMPORTANT_SETTING)
>>> NewValue

Supported operations

Some useful operations are supported by the class itself, emulating built-in str class:

from awstanding.parameter_store import DynamicParameter

IMPORTANT_SETTING = DynamicParameter('/test/parameter')

# Equality comparison
equal = IMPORTANT_SETTING == 'SomeString'

# Length
length = len(IMPORTANT_SETTING)

# Concatenation (Right and Left)
concat = '~' + IMPORTANT_SETTING + '~'

# You can always convert the parameter to string to get full string capabilities:

str_IMPORTANT_SETTING = str(IMPORTANT_SETTING)  # Have in mind this will "freeze" the value, so don't overwrite IMPORTANT_SETTING

S3 Integration

Download files from S3

from awstanding.s3 import Bucket

bucket = Bucket('BUCKET_NAME_HERE')

bucket.download("path/to/file.ext", './some/local/file.ext')

Upload files to S3

from awstanding.s3 import Bucket

bucket = Bucket('BUCKET_NAME_HERE')

bucket.upload('/some/local/file.ext', "some/s3/logical/path.ext")

There's not file type restriction any other that the set by AWS/boto3 itself.

Metadata

Release files for awstanding 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awstanding 1.2.0
File Size Uploaded
awstanding-1.2.0.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for awstanding 1.2.0
File Interpreter ABI Platform
awstanding-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.6 kB

Release files / awstanding-1.2.0.tar.gz

Download URL awstanding-1.2.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5664173cde78908ef5faa28f2d34ea6c5a5475b0518bdf35144c39cbf3e867a4
BLAKE2b-256 checksum
How to use checksums
4433648b91428d4e6bf6a9776b9957ce2d6117d03f56c8cfd0e036bdfb47afc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

Release files / awstanding-1.2.0-py3-none-any.whl

Download URL awstanding-1.2.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dc1581f6e01169921d4666ec9e880c5f5e7155d236b606ca26bd76b02f9bda6
BLAKE2b-256 checksum
How to use checksums
fd900b27f613c145feb088420ca12bbbd7bdcb968a5189be36afc75b613fc3ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page