问题
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.
回答1:
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
回答2:
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
来源:https://stackoverflow.com/questions/54713522/aws-lambda-layer