Lambda function failing with "cannot import name 'etree' from 'lxml' (/var/task/lxml/__init__.py)"

0

I'm creating a lambda function using a virtual env in Windows 10. I'm adding site-packages to a .zip archive and updating the lambda function.

Currently this is failing with "cannot import name 'etree' from 'lxml' (/var/task/lxml/init.py)"

My venv is using Python 3.8 as is the runtime environment in lambda. Some previous solutions suggest setting runtime on lambda to Python 3.6 but this is no longer an option. I've tried 3.7 and 3.9 but the problem persists. Other solutions on re:Post discuss docker containers rather than zip archives and linux environments rather than windows.

1개 답변
0
수락된 답변

I fixed this by spinning up an ec2 machine, creating a directory named python, using pip3 to install the libraries I needed, creating a .zip archive out of the python directory and uplodaing that .zip to s3. From there I could create a layer for aws lambda using the .zip archive.

If you're running into similar problems it may be because you are using Mac OS or Windows to build libraries. Much better to use a Amazon AMI machine to ensure compatibility wiith Lambda.

Ojaybee
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠