Runtime error with pyodbc with AWS Lambda python

Hello,

I’m trying to build AWS Lambda functions in Python that communicate to a SQL Server database. I’m using the pyodbc library. However, I’m currently getting the following runtime error when invoking the lambda function:

[ERROR] Runtime.ImportModuleError: Unable to import module ‘poc/odbc_test’: libodbc.so.2: cannot open shared object file: No such file or directory

It appears that the Lambda Layer (and the Lambda function itself) does not have all the necessary packages that pyodbc requires.

Here are the relevant parts of my serverless.yml:

As you may have noticed, I’ve also tried to use dockerizePip: true (line 6), but that caused the following AWS CodeBuild error:

Serverless: Running docker run --rm -v /root/.cache/serverless-python-requirements/fef1f9ecc3c8f92653f047f3f844c68885fcab814fe6abac7e3dd5538919b4a8_slspyc:/var/task:z -v /root/.cache/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z lambci/lambda:build-python3.8 /bin/sh -c ‘chown -R 0\:0 /var/useDownloadCache && python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache && chown -R 0\:0 /var/task && cp libodbc.so.2 /var/task/ && cp /usr/lib/x86_64-linux-gnu/libodbc.so.2 /var/task/ && chown -R 0\:0 /var/useDownloadCache’…
Error --------------------------------------------------
Error: STDOUT:
STDERR: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See ‘docker run --help’.
at /codebuild/output/src504421371/src/node_modules/serverless-python-requirements/lib/pip.js:325:13

At this point, I am not sure if I’m on the right path, so I figured I should at least post here to see if someone can help. Let me know if you need more information. Thanks!

I’ve read a lot of articles, posts, etc, but have not yet been able to get python 3.6 to talk to SQL Server using AWS Lambda. Any help would be greatly appreciated Kodi nox.