Praha Murali
Praha Murali

Reputation: 39

How to work with Python custom packages in AWS Lambda

I have my app.py function that's using pip libraries like SQLAlchemy, etc... I am deploying this to AWS Lambda, so I am packaging app.py and all other dependencies into a zip.

  1. Is there a better way to deal this? (What if pip libraries go out of date)
  2. I have a custom code that I want to use in many programs. How do I create my own module and package it along with pip libraries?

Upvotes: 3

Views: 3501

Answers (2)

gmacro
gmacro

Reputation: 427

Yeap, I'll give you some alternatives to each of your questions:

  1. Kind of, you could use a *framework (chalice/serverless) to automatically handle packaging for you. Each deploy would fetch the most recent version (according to your requirements.txt) and package then for you. I recommend you to stick with a framework.

  2. A Lambda Layer is exactly what you need - Multiple lambdas will be able to run your module without overhead (in simple terms). There are a lot o references explaining how to create a layer and also about python packaging (You're the one who must evaluate the need to upload it to pypi)

In both cases, serverless is going to help you a lot !

Upvotes: 3

zgoda
zgoda

Reputation: 12895

Regarding 1 - AWS SAM will work out your requirements.txt and bundle what's needed with your code. This works fine for small projects, but for larger ones I'd suggest going the same way as for library code - put all your deps in separate layer. It may be installed with pip install -U --target dirname and then packaged into a layer.

Upvotes: 0

Related Questions