0

I am trying to run an AWS Lambda function and I need pyodbc as a library. When importing pyodbc, I am getting the error:

Unable to import module 'lambda_function': /var/task/lib/libodbc.so.2: file too short.

I cannot find much on this error. Has anyone else experienced this / have advice on how to get past it?

So far, I have:

  • Spun up an EC2 instance and created a deployment package using a combination of these instructions here: https://gist.github.com/diriver63/b72a954fa0da4851d89e5086aa13c6e8 and here: https://www.youtube.com/watch?v=xWbU_OnkFOo. If I do not spin up an EC2 instance and package what I need with Linux, I get the error - "[unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)\").

  • I have ensured all my files are zipped individually rather than zipping a whole folder (if a entire folder is zipped I get a "cannot find lamdba_function" error)

  • Flattened out my file structure so all files are in the home drive, except those that were in lib and lib64 folders. If they are in separate folders, I get a different error - "Unable to import module 'lambda_function': No module named 'pyodbc'" OR "[01000] [unixODBC][Driver Manager]Can't open lib '\libodbc.so'"See current file structure

sab
  • 87
  • 2
  • 11

1 Answers1

0

I ended up using these instructions: https://exagriddba.wordpress.com/category/python/ which got me past that point, however came into the problem of having too bigger file with 5 libraries and hitting the limit of 262mb. Will be using Docker instead, however I think those instructions would have seen us successful had it not been for the limits. Had many errors over the past 2 weeks so happy to try answer any questions!

sab
  • 87
  • 2
  • 11
  • hi, i'm rusty at linux and managed to get docker working and connecting to sql server with unixodbc and msodbcsql. however when i upload the file to lambda, i get the same unable to import module libodbc.so.2 even though i'm using a dffierent driver. how do you know what files to move to your /home dir and flatten to ensure import pydobc sees everything you need to execute a sql query? i've tried changing the odbcinst.ini and odbc.ini files with no success. thanks in advance! – phill Apr 19 '20 at 05:33
  • 1
    Hay Rusty. Did you get it working? For us, from memory to fix this I needed to copy our own version of openssl.cnf and in your Dockerfile, include: COPY openssl.cnf /etc/ssl/openssl.cnf – sab Apr 30 '20 at 01:06
  • https://stackoverflow.com/a/64327675/2506172 should be relevant – narayan Oct 13 '20 at 02:40