Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

futoase/serverless-python-requirements

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Python Requirements

serverless Greenkeeper badge

npm

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

Install

npm install --save serverless-python-requirements

Add the plugin to your serverless.yml:

plugins:
  - serverless-python-requirements

Cross compiling!

Compiling non-pure-Python modules or fetching their manylinux wheels is supported on non-linux OSs via the use of Docker and the docker-lambda image. To enable docker usage, add the following to your serverless.yml:

custom:
  pythonRequirements:
    dockerizePip: true

Dealing with Lambda's size limitations

To help deal with potentially large dependencies (for example: numpy, scipy and scikit-learn) there is support for compressing the libraries. This does require a minor change to your code to decompress them. To enable this add the following to your serverless.yml:

custom:
  pythonRequirements:
    zip: true

and add this to your handler module before any code that imports your deps:

import unzip_requirements

If you want to be able to use sls invoke local and don't have a check for lambda or a try/except ImportError around that impolrt, you can use the following option to make this plugin not delete the unzip_requirements helper:

custom:
  pythonRequirements:
    removeVendorHelper: false

Manual invocations

The .requirements and requirements.zip(if using zip support) files are left behind to speed things up on subsequent deploys. To clean them up, run sls requirements clean. You can also create them (and unzip_requirements if using zip support) manually with sls requirements install.

Updating to python 3.6

This requires an update to your serverless.yml:

provider:
  name: aws
  runtime: python3.6

And be sure to clean up .requirements or requirements.zip if they exist as python2.7 and python3.6 code can't coexist.

Credit

This plugin is influenced by serverless-wsgi from @logandk. I however wanted a simpler pip install process. It now also supports bundling packages without the wsgi handler.

About

⚡🐍📦 Serverless plugin to bundle Python packages

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 96.4%
  • Python 3.6%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.