Skip to main content

# zappa-secrets-manager

A package that will aid in deploying python projects via zappa while using AWS Secrets Manager. This package makes it easier to develop a project using only a few simple changes in order to swap between development and production

## Available Options

PROJECT_NAME (required) - The name of the project part of the key to look up on AWS Secrets Manager

ENV_PATH (required) - The path to the env file that you want to load when developing

EXTRA_ENVS_TO_SET (optional - defaults to []) - A list of two part tuples detailing any extra environment variables that you want to set

ENV_FILE_NAME (optional - defaults to “development.env”) - The name of your local environment file

REGION_NAME (optional - defaults to “eu-west-2”) - The region to get the AWS Secrets from

## Usage

Add a call to “load_secrets” somewhere in your project initialisation script, preferably before any project specific settings are initialised.

## Full Django Example In <project_name>/__init__.py add the following.

# This should be the full path to your local environment file (excluding the file itself)
ENV_PATH = '<the full path to your local environment file>'

# Any extra environment settings you wish to set.  The second element of each tuple will get str formatted
# with your PROJECT_NAME and the STAGE from zappa in order to create a lookup on AWS Secrets Manager
EXTRA_ENVS_TO_SET = [('DATABASE_PASSWORD', '{PROJECT_NAME}/{STAGE}/db/{PROJECT_NAME}'),]

load_secrets(PROJECT_NAME='myproject',
             ENV_PATH=ENV_PATH,
             EXTRA_ENVS_TO_SET=EXTRA_ENVS_TO_SET,
             ENV_FILE_NAME='testing.env',
             REGION_NAME='us-west-1')

## How it works

Zappa Secrets Manager allows you to easily swap between a production environment on the server with only minimal changes to your local codebase. By default zappa will fail closed - so you need to actively go out of your way to accidentally get production env variables on your local system.

  1. zappa-secrets-manager checks for the existence of a zappa STAGE environment variable. This will always be there if you deploy with zappa. If this exists and there is no local “development.env” file then it will use the relevant AWS credentials to obtain the AWS Secrets for anything with a key of ‘myproject<stage>’. It then loads these secrets into your environment for use in your project.

  2. If STAGE is not set OR if there is a local “development.env” file then it will load the contents of that file into your environment for use in your project

  3. If neither STAGE or “development.env” exists then the system fails with a RuntimeError

## WARNING

DO NOT COMMIT YOUR LOCAL DEVELOPMENT.ENV FILE

## How to structure your AWS Secrets Key Names

Zappa Secrets Manager will by default load any secrets that are stored in <PROJECT_NAME><STAGE> on the appropriate REGION_NAME into your environment.

For any values in EXTRA_ENVS_TO_SET you can structure your key names however you want. Zappa Secrets Manager will string format them to include the zappa STAGE and the PROJECT_NAME variables so you can do dynamic lookups.

## Example

Given an ENV_PATH of “path-to-env-file” PROJECT_NAME of “my_project” and a zappa STAGE of “prod” the following will happen:

  1. Check to see if “path-to-env-file/development.env” exists. If it does then it loads the environment variables out of that.

  2. If it doesn’t exist then it loads all the secrets on the eu-west-2 region with the secret name “my_project/prod” into your environment.

Metadata

Release files for zappa-secrets-manager 0.5.3

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

Source distribution (sdist)

Source distribution for zappa-secrets-manager 0.5.3
File Size Uploaded Provenance
zappa_secrets_manager-0.5.3.tar.gz 4.2 kB Without provenance Details

Release files / zappa_secrets_manager-0.5.3.tar.gz

Download URL zappa_secrets_manager-0.5.3.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2f75dd04eb89f3cdc5376001cebac7afcf8d0220ea31ee65defdcbcb6bc6b736
BLAKE2b-256 checksum
How to use checksums
e96584c8d1bda4ee5a7bdeeaa3edd62d79c7971fe3db126d35561873754b0731
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 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.3

Security for zappa-secrets-manager 0.5.3

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.

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