0

I am trying to import pandas library to my aws lambda layer. But is gives an error saying to cannot import lambda.function: no module names numpy.

Can some explain what is the problem with pandas and aws. when I try to locally run it on pycharm using SAM it throws the same error.

valdeci
  • 13,962
  • 6
  • 55
  • 80
Mohit Ruke
  • 11
  • 2
  • 2
    Sometimes this could happen because the library is using a OS library dependency that Lambda can't have access to that, so one of the things I did was to use a library to have the OS dependency embedded in the library I was using in Lambda – Jorge F Feb 15 '19 at 16:43
  • https://stackoverflow.com/questions/43859497/aws-lambda-and-python-numpy-module – Mark B Feb 15 '19 at 17:11

2 Answers2

2

Lambdas have a limit of 125 MB as a part of the zip file or code that you upload and typically Pandas/Numpy are huge libraries that go past those limits potentially. Hence

1) If the part of your code that is using pandas can be replaced with other pythonic way of doing things (defaultdict, dict, lists etc) I recommend that 2) You can try zipping the dependancies (pandas or other libraries that you did a pip install with) in a linux environment, as Lambdas are in a linux environment. You can follow this article: https://medium.com/i-like-big-data-and-i-cannot-lie/how-to-create-an-aws-lambda-python-3-6-deployment-package-using-docker-d0e847207dd6 3) You can maybe follow this: https://medium.com/@qtangs/creating-new-aws-lambda-layer-for-python-pandas-library-348b126e9f3e

sbnukala
  • 33
  • 3
1

If you are using AWS Lambda Layers you need to validate if your directory structure is on the needed structure for a layer:

For example for the pillow python module you need the following structure:

aws-lambda-layer.zip
│ python
│ python/PIL
└ python/Pillow-5.3.0.dist-info

So to create a layer zip file with the correct structure we can use the following command on the root of our project:

mkdir -p python && cp -r <lib_name> python/ && zip -r aws-lambda-layer.zip python
valdeci
  • 13,962
  • 6
  • 55
  • 80