The default way of creating a zip package that’s to be deployed to AWS Lambda is to place everything – your source code and any libraries you are using – in the service root directory and compress it. I don’t like this approach as, due to the flat hierarchy it can lead to naming conflicts, it is harder to manage packaging of isolated functions and it creates a mess in the source directory.
What I do instead is install all dependencies into a
lib directory (which is as simple as
pip install -r requirements.txt -t lib step in the deployment pipeline) and set the
PYTHONPATH environment variable to
/var/runtime:/var/task/lib when deploying the Lambda functions.
This works because the zip package is extracted into
/var/task in the Lambda container. While it might seem as an unstable solution, I’ve been using this for over a year now without any problems.