Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using numpy in AWS Lambda

I'm looking for a work around to use numpy in AWS lambda. I am not using EC2 just lambda for this so if anyone has a suggestion that'd be appreciated. Currently getting the error:

cannot import name 'multiarray'

Using grunt lambda to create the zip file and upload the function code. All the modules that I use are installed into a folder called python_modules inside the root of the lambda function which includes numpy using pip install and a requirements.txt file.

like image 933
Sebastian Łącki Avatar asked Sep 12 '17 21:09

Sebastian Łącki


People also ask

Can I use NumPy in AWS Lambda?

AWS Lambda does not include Pandas/NumPy Python libraries by default.

Can I use Python packages with AWS Lambda?

Short description. Python packages that contain compiled code (for example: NumPy and pandas) aren't always compatible with Lambda runtimes by default. If you install these packages using pip, then the packages download and compile a module-name package for the architecture of the local machine.

How do I import a Python library into AWS Lambda?

Steps to add python packages in AWS lambda layers Step 1: Go to the AWS management console. Step 2: Click on create function. Step 5: Now try importing the requests module in your lambda function. So, create an event named “myevent” by clicking the down arrow on the test button.


1 Answers

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.

like image 191
user_5 Avatar answered Oct 26 '22 23:10

user_5