AWS Lambda with Pandas and NumPy

Problem statement

There are no default Pandas in AWS Lambda. You can see AWS Lambda execution environment and available libraries here. Let’s verify and create AWS Lambda Python 3.6 function with code below:

Unable to import module 'lambda_function': No module named 'pandas'
$ pip install -t . pandas
$ rm -r *.dist-info __pycache__
$ zip -r zip.zip .
zip.zip archive with lambda_function.py file and Pandas
Upload function package
Unable to import module 'lambda_function': Missing required dependencies ['numpy']
zip.zip archive with lambda_function.py file, Pandas, and Numpy
$ rm -r pandas numpy *.dist-info

Solution

AWS Lambda use Amazon Linux operating system. Idea is download Pandas and NumPy compatible with Amazon Linux.

$ unzip numpy-1.16.1-cp36-cp36m-manylinux1_x86_64.whl
$ unzip pandas-0.24.1-cp36-cp36m-manylinux1_x86_64.whl
$ rm -r *.whl *.dist-info __pycache__
$ zip -r zip.zip .
zip.zip archive for Amazon Linux with lambda_function.py file, Pandas, and Numpy
Upload function package
Execution result: succeeded

--

--

Python Developer and Artificial Intelligence Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store