I am doing a small project on python with scrapy. To upload it on AWS lambda , i simply created a folder,copied all the required libraries from my pc's site-packages , and deployed it on lambda ,which gave an error UNABLE TO IMPORT ETREE , i googled and found this solution Unable to import lxml etree on aws lambda . I haven't used docker everr, all i want to know is After i have run a docker image of amazon linux on my pc, how do i install all the libraries in there,and then get those exported out to my pc,so i can upload it.
Asked
Active
Viewed 284 times
1 Answers
1
You can install docker
and run a simple bash
script like this to create a layer
If you want to create a layer (and link to the lambda):
cd mylayer
docker run --rm -it -v ${PWD}:/var/task lambci/lambda:build-python3.6 pip install -r requirements.txt --no-deps -t python/lib/python3.6/site-packages/
zip -r ../my-layer.zip python
rm -rf python
cd -
If you want to create a lambda package:
cd mylambda
docker run --rm -it -v ${PWD}:/var/task lambci/lambda:build-python3.6 pip install -r requirements.txt --no-deps -t python/lib/python3.6/site-packages/
zip -r ../my-lambda-package.zip python lambda_function.py
rm -rf python
cd -

DaveR
- 1,696
- 18
- 24
-
I want to know that, when i run an amazonlinux image,then create a virtual environement, and then i pip install everything there, and then when i copy the directory out to my pc and deploy it online,it still gives the same errors. – Kartik sharma Feb 05 '20 at 17:50
-
@Kartiksharma what do you mean? did you try the script i suggested? – DaveR Feb 06 '20 at 16:02
-
This looks promising but there is no support for python 3.9. Any alternative? – Zioalex Jul 25 '22 at 20:52
-
You can use amazon linux docker images https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html or try with 3.8, some packages could be compatible across versions. – DaveR Jul 28 '22 at 07:05