Skip to content
Advertisement

How to upload pandas, sqlalchemy package in lambda to avoid error “Unable to import module ‘lambda_function’: No module named ‘importlib_metadata'”?

I’m trying to upload a deployment package to my AWS lambda function following the article https://korniichuk.medium.com/lambda-with-pandas-fd81aa2ff25e. My final zip file is as follows: https://drive.google.com/file/d/1NLjvf_-Ks50E8z53DJezHtx7-ZRmwwBM/view but when I run my lambda function I get the error Unable to import module 'lambda_function': No module named 'importlib_metadata' errorimg

My handler is named lambda_function.lambda_handler which is the file name and the function to run. I also tried uploading these zip files as layers excluding the lambda_function.py and get: layerErr What am I doing wrong?

EDIT: I tried using zip/lambda_function.lambda_handler as my handler still getting Unable to import module 'zip/lambda_function': No module named 'zip/lambda_function'

Advertisement

Answer

There is a third party github repo with public layers, including pandas. You don’t have to do anything to use, except adding the layer arn to your function. The arn depends on your region, so you have to choose your region. For example, for us-east-1 the pandas layer for python 3.8 is:

arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-pandas:31
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement