Enables seamless zappa integration with AWS Secrets Manager while still allowing local development via environment variables
Project description
# 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.
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.
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
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:
Check to see if “path-to-env-file/development.env” exists. If it does then it loads the environment variables out of that.
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.
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
File details
Details for the file zappa_secrets_manager-0.5.3.tar.gz
.
File metadata
- Download URL: zappa_secrets_manager-0.5.3.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f75dd04eb89f3cdc5376001cebac7afcf8d0220ea31ee65defdcbcb6bc6b736 |
|
MD5 | f30b9b1c9394bf184a1f1ea8a3332aa2 |
|
BLAKE2b-256 | e96584c8d1bda4ee5a7bdeeaa3edd62d79c7971fe3db126d35561873754b0731 |