This is an opinionated template for creating a Serverless.com project using Python as the programming language.
It combines Node (required for the serverless
command) with Python (the programming language for the serverless functions) in one virtual environment.
See dltj.org/article/starting-python-serverless-project for more information.
git clone serverless-template && cd serverless-template
PIPENV_VENV_IN_PROJECT=1 pipenv install --dev
pipenv shell
nodeenv -p
# Installs Node environment inside Python environmentnpm install --include=dev
# Installs Node packages inside combined Python/Node environmentexit
# For serverless to install correctly in the environment...pipenv shell
# ...we need to exit out and re-enter the environmentnpm install -g serverless
# Although the '-g' global flag is being used, Serverless install is in the Python/Node environment
In addition to what is described in the blog article linked above, this template:
- installs black, pylint, and boto3
- installs serverless-domain-manager, serverless-iam-roles-per-function, and serverless-prune-plugin
- puts the Python code in a subdirectory
- uses a config.yml file that is excluded from version control
- makes some decisions about the AWS settings in the serverless.yml file
Configuration for the 'serverless-domain-manager' is commented out because that is one of the last steps in a production deployment.
As noted in the serverless.yml
file, there is a config.yml
file that contains bits of configuration that are not suitable for storing in a version control system.
The concept comes from Rich Buggy's 'Keeping secrets out of Git' blog post.
A sample of that file looks like:
default: &default
<<: *default
# COMMON_SECRET: "A SECRET THAT IS IN COMMON ACROSS ALL ENVIRONMENTS"
dev:
<<: *default
# API_KEY: "YOUR DEVELOPMENT API KEY"
# API_SECRET: "YOUR DEVELOPMENT API SECRET"
BASE_PATH: "/dev"
stage:
<<: *default
# API_KEY: "YOUR STAGING API KEY"
# API_SECRET: "YOUR STAGING API SECRET"
prod:
<<: *default
# API_KEY: "YOUR PRODUCTION API KEY"
# API_SECRET: "YOUR PRODUCTION API SECRET"
BASE_PATH: ""