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?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ