Runtime.ImportModuleError with Lambda and python-docx

0

Hi, I have created a lambda layer. I uploaded a zip having python/{python-docs} files. I have added this lambda layer to my AWS lambda. While testing lambda, I am getting below error Runtime.ImportModuleError: Unable to import module 'lambda_function': cannot import name 'etree' from 'lxml' (/opt/python/lxml/init.py)

this comes at the first line of import from docx import Document

is there any way to fix this? I don't want to go the container way.

Jay
asked 4 months ago236 views
1 Answer
0

Hi,

  1. Did the lib run successfully on your local env?
  2. Base the error msg, you can check the lxml which did contain the 'etree'.
  3. You can change your import code snip to "import lxml" to observe whether the function can work. if it can run without error, this indicates that your layer is right for lambda but the module is wrong such as the 'lxml' did not contain 'etree' and so on and then you need to adjust the zip file.
profile picture
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions