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
asked 2 years ago1469 views
3 Answers
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
EXPERT
answered 2 years ago
  • 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
answered 2 years ago
  • 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
answered a year ago
  • Python 3.7 is leaving, have there been any other findings?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions