Serverless Framework - Python and Requirements.txt

。_饼干妹妹 提交于 2019-11-29 10:12:05

You need to install serverless-python-requirements and docker

$ npm install serverless-python-requirements

Then add the following to your serverless.yml

plugins:
   - serverless-python-requirements

custom:
  pythonRequirements:
     dockerizePip: non-linux

Make sure you have your python virtual environment active in CLI:

$ source venv/bin/activate

Install any dependencies with pip - note that in CLI you can tell if venv is active by the venv to the left of the terminal text

(venv) $ pip install <NAME>
(venv) $ pip freeze > requirements.txt

Make sure you have opened docker then deploy serverless as normal

$ serverless deploy

What will happen is that serverless-python-requirements will build you python packages in docker using a lambda environment, and then zip them up ready to be uploaded with the rest of your code.

Full guide here

Now you can use serverless-python-requirements. It works both for pure Python and libraries needing native compilation (using Docker):

A Serverless v1.x plugin to automatically bundle dependencies from requirements.txt and make them available in your PYTHONPATH.

Requires Serverless >= v1.12

Benny Bauer

The Serverless Framework doesn't handle the pip install. See https://stackoverflow.com/a/39791686/1111215 for the solution

Follow the steps mentioned in this git repo readme file - https://github.com/shyam454/Flask_AWS

Create Virtual Env Install Python dependancies requirements.txt file deploy

The readme file has it step by step with commands

You should get it easy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!