I am trying to build a AWS Lambda function using APi Gateway which utlizes pyodbc python package. I have followed the steps as mentioned in the documentation. I keep getting the following error Unable to import module 'app': libodbc.so.2: cannot open shared object file: No such file or directory when I test run the Lambda function.
Any help appreciated. I am getting the same error when I deployed my package using Chalice. It seems it could be that I need to install unixodbc-dev. Any idea how to do that through AWS Lambda?
Fisrt, install
unixODBC
andunixODBC-devel
packages usingyum install unixODBC unixODBC-devel
. This step will install everything required for pyodbc module.The library you're missing is located in
/usr/lib64
folder on you Amazon Linux instance. Copy the library to your python project's root folder (libodbc.so.2 is just a symbolic link, make sure you copy symbolic link and library itself as listed):libodbc.so
,libodbc.so.2
andlibodbc.so.2.0.0
pyodbc uses some native libs. Therefore you cannot just copy the contents of your
site-packages
to Lambda, as your OS is likely not Amazon Linux.So you need to install pyodbc on an Amazon Linux instance and use the generated libs:
https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
Or you can get from here, if available there:
https://github.com/Miserlou/lambda-packages
try running this script to collect dependency into s3 bucket and then adding it to your lambda deployment package.