简体   繁体   中英

Build and use local package for AWS Lambda using serverless framework

I am trying to package a local python package¹ and use it within an AWS lambda deployed via the Serverless framework. I already use serverless-python-requirements plugin to add pip dependencies to deployed package.

How can I proceed ?

Shall I create a package and zip it? Or generate a whl file and use pip? And then, how to deploy it?


¹: I cannot just add it to "normal codebase" as I want to share it with other bricks (Glue jobs for example)

Here's the solution:

1.

Build a .whl file corresponding to package using

python setup.py bdist_wheel

within a parent directory.

2.

Add the relative path to this .whl file to used pip requirement file ( requirements.txt for instance) :

req0==1.0.9
req1==5.5.0
../<relative path to local package>/dist/<package name>-<version>-<details>.whl # generated .whl file's name
3.

serverless-python-requirements will automagically pack this dependency within the deployed archive when doing sls deploy . How cool is that, huh!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM