A Python starter project for Serverless Framework with support for dependencies (using virtualenv & serverless-python-requirements) and tests (using unittest).
A demo version of this service is hosted on AWS - https://udshnoxw3k.execute-api.us-east-1.amazonaws.com/dev
Create a new project
$ serverless install --url https://github.com/AnomalyInnovations/serverless-python-starter --name my-project
Create a virtual environment for your project
$ cd my-project
$ virtualenv -p /usr/bin/python3.6 venv
Activate the virtual environment
$ source venv/bin/activate
Install Serverless plugin: serverless-python-requirements
$ npm install
Install a Python dependency (for example, Requests)
$ pip install requests
Store a reference to your dependencies
$ pip freeze > requirements.txt
Re-install your dependencies from your requirements
$ pip install -r requirements.txt
Invoke a function locally
$ serverless invoke local -f hello
Run your tests
$ python -m unittest discover -s tests
Deactivate your virtual environment
$ deactivate
Deploy your project
$ serverless deploy
Deploy a single function
$ serverless deploy function --function hello
To compile non-pure Python modules, install Docker and the Lambda Docker Image. Enable dockerizePip in serverless.yml and serverless deploy
again.
# enable dockerize Pip
custom:
pythonRequirements:
dockerizePip: true
Note, if you are deploying using SEED, you don't need to enable dockerizePip or install Docker. SEED does it automatically.
- Send us an email if you have any questions
- Open a new issue if you've found a bug or have some suggestions.
- Or submit a pull request!
Maintained by Frank Wang (@fanjiewang) & Jay V (@jayair). Subscribe to our newsletter for updates. Send us an email if you have any questions.