Raj
Raj

Reputation: 623

Missing required dependencies ['numpy'] in AWS Lambda function

I guess many people have come across the same issue. I have tried to find every possible blog and try every method. I have reached this point and stuck here.

I am using Serverless framework and virtualenv.

serverless.yml:

 service: test-pandas
 provider:
   name: aws
   runtime: python2.7
 plugins:
   - serverless-python-requirements
 package:
    exclude:
       - venv/**
       - node_modules/**
 functions:
    hello:
       handler: validation.hello

validation.py:

import pandas as pd
import numpy as np 

def hello(event, context):
    return "hello world"

I am using python 2.7. I have run these commands in Virtualenv:

virtualenv venv --python=python2
source venv/bin/activate
pip install pandas
pip freeze > requirements.txt
cat requirements.txt

Before creating the requirements.txt, the error was "No import module named pandas" and after I setup serverless-python-requirements, I am getting "Missing required dependencies ['numpy']".

Am I missing something here?

Upvotes: 3

Views: 1017

Answers (1)

Raj
Raj

Reputation: 623

I used Docker to package and deploy the Lambda function with the libraries.

Add the following in serverless.yml:

custom:
  pythonRequirements:
    dockerizePip: non-linux

Make sure Docker is running on your machine and deploy it using serverless commands. Another thing I noticed is that, after using Docker, the .zip filesize reduced almost half of the original filesize.

Upvotes: 2

Related Questions