This is the Fondeadora Python serverless framework template. It is intended to be used with Python v3.7 but could be updated to more recent versions.
This template includes the following extra configurations:
- serverless framework
- serverless-offline plugin
- serverless-plugin-git-variables
- serverless-plugin-warmup
- serverless-prune-plugin
- serverless-python-requirements
- Autopep8 code formatter
- Flake8 for code linting
- Pre-commit framework to add extra git hooks
It will, by default set the stage to dev
and the region to us-east-1
.
Pre-commit is configured to run pyformat
and flake8
on the pre-commit hook.
First you should have Node.js, yarn and Python v3.6 installed on your machine.
- Install the
serverless
framework with
npm install -g serverless
- Install the serverless framework plugins required.
npm install
- Create a virtualenv for python
yarn venv-setup
- Install python dependencies
pip install -r requirements-dev.txt
- Install the pre-commit hooks.
pre-commit install
And that’s all.
To initialize a new repository using this template use the following command:
serverless create--template-url https://github.com/Fondeadora/python-service-template--path my-service
Make sure you replace myService
with the name of your service and update the service.name
in serverless.yml
file.
Then start your development environment with
sls offline
# Deploy dev
yarn deploy
# Deploy production
yarn deploy-prod
# Test
python -m unittest discover
make format
make lint
By default, pre-commit will not update the staging area, so make sure to review any changes that the black code formatter do to your files before restaging them.
Flake8 will fail if it encounters any errors, so you can review and fix them appropriately.
Make sure to add any new dependencies in the requirements.txt
file.
Please open an issue so we can discuss changes to this template.