AWS Lambda Python3.7 Function - numpy: cannot import name 'WinDLL' AWS Lambda Python3.7 Function - numpy: cannot import name 'WinDLL' numpy numpy

AWS Lambda Python3.7 Function - numpy: cannot import name 'WinDLL'


Aws lambda will throw you an error if you don't have the correct version of dependencies packaged with your code, which may depend on the OS (lambda runs on linux) and the python version.

Based on your requirements, it's pandas throwing you the error. To run pandas on lambda, you need to include the following packages:

pandas - code compiled for the linux, which is what lambda runs you. You can find it here https://pypi.org/project/pandas/#files download the 'manylinux' version of the .whl file, that matches your python lambda version.

  • e.g. if you are running py3.7, then get pandas-0.25.3-cp37-cp37m-manylinux1_x86_64.whl

  • Unzip the contents of the .whl file into the root folder of your lambda folder. This is the library version that lambda needs

  • Note for pandas 0.25+, you also need to include the pytz package as well, see note below on requests

numpy - You can now get in lambda (tested for py3.7) through installing a 'layer' through the lambda console, see screenshots below.

Side note on requests

  • Notice that the package here https://pypi.org/project/requests/#files only have a 'none-any' version, that means the source doesn't need to be compiled, so you can safely include the version you got from pip

  • this applies to the pytz dependency of pandas as well

Screenshots installing layers in aws console

adding a layer im lambdaselect layer


Since numpy is written in C you should build it for a linux distribution. I recommend you using the serverless framework because it will simplify your life a lot when you are using a Windows laptop.

Install the serverless framework and make sure you have docker

go to the root of your project and execute:

sls create --template aws-python

install the plugin for deploying python apps:

serverless plugin install -n serverless-python-requirements

in your serverless.yml file add:

plugins:   - serverless-python-requirementscustom:  pythonRequirements:     dockerizePip: non-linux

make sure you adjust the path to your lambda function

functions:  hello:    handler: handler.hello

deploy with the correct libraries using

sls deploy