1

I'm developing a python function for AWS lambda.

My function works locally, with:

 python-lambda-local -f handler app.py event.json -t 30

However, when I deploy it in AWS Lambda, (with a zip file with all dependencies), it seems the objectify lib is not loaded. Error message:

Unable to import module 'app': cannot import name 'objectify'

This is a snippet of my function:

# -*- coding: utf-8 -*- 
import sys
import logging
import env_config
import pymysql
import traceback
import json
import requests
#from lxml import objectify
import lxml.objectify
import lxml.etree

1 Answer 1

3

Lxml uses code compiled in C. You need to precompile the library in the same environment that Lambda runs. Read this to understand more: https://www.azavea.com/blog/2016/06/27/using-python-lxml-amazon-lambda/

This kind person already did the job for you. Just download the precompiled library and replace in your Lambda package: https://github.com/JFox/aws-lambda-lxml

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thanks for your help !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.