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
已回答 1 年前
  • Python 3.7 is leaving, have there been any other findings?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南