问题
We have a Django application we deploy on AWS Lambda, using Zappa. We use pipenv to manage python packages of the project. Some packages we use (e.g cryptography) need to be compiled with the same configration as the lambda machine. To do that, I've generated wheels for those packages on a similar machine, and included them in a sub folder in the directory. So here is our deployment process now:
- install packages with pipenv (which also includes those special packages)
- extract precompiled wheels in a special directory
- run zappa deploy command
So after this, we have two versions of those packages, one installed via pipenv, and one extracted manually from precompiled wheels. The reason for this is, I still want the project to be able to run locally (using the package installed via pipenv, and not using the precompiled ones). So I want local versions of the project to use packages installed via pipenv, but want Lambda to use extracted - precompiled version.
I've added the directory where we keep precompiled packages to PYTHONPATH environment variable, but as far as I can see, zappa puts all python packages installed via pipenv in the root folder of the project. Those have precedence over whatever I add in PYTHONPATH in import package resolution order.
So do I have any options in telling python to give a specific folder import resolution precedence over all others?
来源:https://stackoverflow.com/questions/60449533/aws-lambda-django-app-deployed-with-zappa-python-import-precendecy