"Unable to import module ‘launcher’: cannot import name ‘etree’ from ‘lxml’ (/var/task/lxml/init.py)"
I have been trying to schedule a Python scraper to run and drop data to AWS S3 using AWS Lambda and Serverless. I have successfully deployed a function within AWS Lambda via Serverless, but I’m getting the error referenced above when I go to run it.
I’ve already worked through troubleshooting steps referenced here: https://aws.amazon.com/premiumsupport/knowledge-center/lambda-import-module-error-python/
Th result of this troubleshooting was setting up a Cloud9 IDE that allowed me to create a Python package with lxml installed among other modules. I created a layer on my Lambda function with that package hoping it would pick up the module, but I got the same error.
I am now wondering if the problem is that the Python scraper was built locally and Serverless was deployed locally. Would I be better off migrating my code to Cloud9 and trying to deploy the job from there?
Any help would be appreciated.
2
Answers
I was having this same issue when attempting to use the simple-salesforce library on a lambda function. I created a ticket with AWS and the steps they provided worked for me. Posting the steps w/ commands below:
[If you are using python3.9 for your Lambda function]
a. Install python3.9
b. create simple-salesforce package or whatever package is using lxml
create Lambda layer with the package(you can use AWS CLI ‘publish-layer-
version’)
Voila! Hope this works for you.
Hi I came across the same error actually it is really simple you should just create AWS lambda layer with scrapy installed in the layer
#1 Create a new folder with a requirements.txt
#2 Add scrapy to your requirements.txt
Once you have followed this steps
#3 Follow the rest of the steps here
https://aws.amazon.com/fr/premiumsupport/knowledge-center/lambda-layer-simulated-docker/