AWS Lambda not importing LXML

前端 未结 8 1373
傲寒
傲寒 2021-01-02 04:57

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

8条回答
  •  迷失自我
    2021-01-02 05:20

    The lxml library is os dependent thus we need to have precompiled copy. Below are the steps.

    1. Create a docker container.
      docker run -it lambci/lambda:build-python3.8 bash

    2. Create a dir named 'lib'(anything you want) and Install lxml into it.
      mkdir lib
      pip install lxml -t ./lib --no-deps

    3. Open another cmd and run
      docker ps

    4. copy the containerid

    5. Copy the files from container to host.
      mkdir /home/libraries/opt/python/lib/python3.8/site-packages/
      docker cp :/var/task/lib /home/libraries/opt/python/lib/python3.8/site-packages/

    6. Now you have lxml copy of files compiled from amazonlinux box, If you like to have lxml as Lambda layer. Navigate to /home/libraries/opt and zip the folder named python. Now you can attach the zip in your lambda as layer.

    7. If you want lxml library inside lambda. Navigate to /home/libraries/opt/python/lib/python3.8/site-packages/ and copy the lxml folder in your lambda.

提交回复
热议问题