I am trying to use the LXML module within AWS Lambda and having no luck. I downloaded LXML using the following command:
pip install lxml -t folder
I was able to get this working by following the readme on this page:
python3.8
with the version of python you are using for your lambda function, and lxml
with the version of lxml you want to use)
$ docker run -v $(pwd):/outputs -it lambci/lambda:build-python3.8 \
pip install lxml -t /outputs/
lxml
in your working directory, and possibly some other folders which you can ignore. Move the lxml
folder to the same directory as the .py
file you are using as your lambda handler..py
file with the lxml folder, as well as any packages if you are using a virtualenv. I had a virtualenv and lxml already existed in my site-packages folder, so I had to delete it first. Here are the commands I ran (note that my virtualenv v-env folder was in the same directory as my .py
file):
FUNCTION_NAME="name_of_your_python_file"
cd v-env/lib/python3.8/site-packages &&
rm -rf lxml &&
rm -rf lxml-4.5.1.dist-info &&
zip -r9 ${OLDPWD}/${FUNCTION_NAME}.zip . &&
cd ${OLDPWD} &&
zip -g ${FUNCTION_NAME}.zip ${FUNCTION_NAME}.py &&
zip -r9 ${FUNCTION_NAME}.zip lxml
FUNCTION_NAME="name_of_your_python_file"
zip -g ${FUNCTION_NAME}.zip ${FUNCTION_NAME}.py &&
zip -r9 ${FUNCTION_NAME}.zip lxml
More on creating a .zip file for lambda with a virtualenv here