Using python-magic in a lambda

2

Hi, I'm trying to run a python lambda function. I'm using the zip deployment. I want to be able to run my code in python 3.9.

The function runs fine using python 3.7 runtime, however when I set the runtime to python 3.9 it fails it gives the error:

"Unable to import module 'lambda_function': failed to find libmagic. Check your installation".

I followed the instructions given in this stack overflow post: https://stackoverflow.com/questions/61921935/aws-lambda-failed-to-find-libmagic.

I added a copy of libmagic.so.1 to a directory called lib in the code. However it still gave the same error message. Any help would be appreciated.

  • Better convert you lambda code in SAM. and test it on local with both runtime.
    you might need to add dependency in requriements.txt

adam
질문됨 2년 전1496회 조회
3개 답변
0

Given that the function runs correctly under Python 3.7 but doesn't when you change the runtime I suspect that there are some components in the ZIP which are not compatible with Python 3.9. Rebuild the entire ZIP from scratch using Python 3.9 on your source machine and then upload the new ZIP to Lambda.

profile pictureAWS
전문가
답변함 2년 전
  • I did build the package using python 3.9.

  • What platform did you build it on?

  • I built it on an ec2 instance running ubuntu (x86)

  • Please try building it using an Amazon Linux instance - that's the same platform that Lambda runs on.

  • Has anyone found a working lambda layer of python-magic or could someone share theirs? @adam or @Brettski-AWS

0

Convert you lambda in SAM template. and test it on you system. SAM local invoke <Lambda_NAM> --events <EVENT FILE>

profile picture
답변함 2년 전
  • This is a good idea, this is to focus on mapping yes?

0

Some have found success here: https://stackoverflow.com/questions/61921935/aws-lambda-failed-to-find-libmagic . I found it working switching to the 3.7 runtime

dwchow
답변함 일 년 전
  • Python 3.7 is leaving, have there been any other findings?

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

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

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

관련 콘텐츠