简体   繁体   中英

Problem with library loading in AWS lambda function - Python

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM