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?

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.