Hello,
I have a python project using pipenv and I have several external libraries on it.
I would like to generate a zip file for uploading to AWS Lambda that contains all the dependencies but I can't find the way to do this? Sorry if this is a dumb question but I am quite new to Python and pipenv.
Thanks.
Pipenv does not have a vendoring command, and it is unlikely to be added in near future (see #1143). I personally don鈥檛 think it fits well in Pipenv either.
Something like this would probably suit your need (modified from https://github.com/pypa/pipenv/issues/1143#issuecomment-352535697):
# Creates foo.txt that lists all your dependencies.
pipenv lock -r > foo.txt
# Download libraries into "./vendor".
pipenv run pip download -d ./vendor -r foo.txt
# Archive (with zip) the "./vendor" directory into "vendor.zip".
pipenv run python -m zipfile -c vendor.zip ./vendor/
I currently do this without pip download, in this fashion:
mkdir output
pipenv lock -r > requirements.txt
pip install -r requirements.txt --no-deps -t output
zip -r output.zip output
Not sure if it'd be in-scope for pipenv
to support a -t
flag. It's not that complicated to do this for AWS Lambda :)
Hi @uranusjr, @jtratner, Thanks for your help, this is what I needed :)
Maybe it would just worth to include these in the docs
Thanks
You'll find improved consistency if you use a docker image to build your dependency layer.
First: pipenv lock --requirements --keep-outdated > ./python/requirements.txt
Then: docker run --rm -v /your/path/to/deps/python\:/var/task\:z -u 0 lambci/lambda\:build-python3.7 python3.7 -m pip install -t /var/task/ -r /var/task/requirements.txt
This ensures you use the lambda's environment so that python can do it's funky environment-dependent dependency magic. Don't forget to zip deps
to be able to upload the layer.
Most helpful comment
I currently do this without pip download, in this fashion:
Not sure if it'd be in-scope for
pipenv
to support a-t
flag. It's not that complicated to do this for AWS Lambda :)