7

Trying to successfully run numpy on AWS Lambda. The information I have read indicates that you need to use numpy libraries specifically compiled/compatible with AWS EC2.

Do do this I first followed the instruction to compile numpy on an ec2 instance, here:

Installing numpy on Amazon EC2

I then copied the newly built numpy into my Lambda application folder on my desktop, zipped up a Lambda deployment package containing the entire directory.

Upon running my Lambda function I still get this error:

Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

Suggestion?

Dave
  • 99
  • 5
  • 1
    Possible duplicate of [Using moviepy, scipy and numpy in amazon lambda](https://stackoverflow.com/questions/34749806/using-moviepy-scipy-and-numpy-in-amazon-lambda) – Kannaiyan Sep 23 '17 at 02:03

2 Answers2

7

Adding an answer for anyone who finds this old question.

Luckily, this problem has now been solved with Lambda Layer. AWS even provides a NumPy and SciPy layer. You can attach it directly to your Lambda in the web console or use this ARN arn:aws:lambda:us-east-1:668099181075:layer:AWSLambda-Python36-SciPy1x:2

Milan Cermak
  • 7,476
  • 3
  • 44
  • 59
  • This worked for me! Just a quick note, it is only available with python 3.6 I believe. With my runtime of python 3.9 I wasn’t able to find it so I switched to 3.6 and was able to add it then – Ash Apr 02 '22 at 21:25
0

An easy way to make your lambda function support the numpy library for python 3.7:

  1. Go to your lambda function page
  2. Find the Layers section at the bottom of the page.
  3. Click on Add a layer.
  4. Choose AWS layers as layer source.
  5. Select AWSLambda-Python37-Scipy1x as AWS layers.
  6. Select 37 for version.
  7. And finally click on Add.

Now your lambda function is ready to support numpy.

user_5
  • 498
  • 1
  • 5
  • 22