简体   繁体   中英

How to include a subdirectory of libraries in an AWS Lambda function

I'm writing a Lambda function (in Python3 for this example) that requires two non-standard libraries. Those libraries in turn require ~30 additional libraries. To add those two directories locally to push to AWS Lambda I run the command pip3 install <library> -t./ .

Unfortunately now, I have all of these libraries and my lambda_handler.py all in the same directory. Now this technically works, but doesn't look good and is difficult for source control/readability/editing. I tried putting the libraries into a single directory, but then my python script is unable to find them.

Ideally, I'd like my entire Lambda project to look like this

function.zip

lambda_handler.py
config.py
libraries/

What would I need to do to my code/directory to have this sort of nice, clean structure?

Thank you!

One way to ensure cleaner and nice structure of your deployment package, would be to use lambda layers for the dependencies:

With layers, you can use libraries in your function without needing to include them in your deployment package .

This also allows you to reuse the same dependencies across multiple lambda functions, which is beneficial for source control, readability and maintainability of your lambda functions.

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