I have a flask restful API which works fine on EC2. Its able to connect to AWS SQL Server and can perform fetch/update. But when I upload to AWS lambda I get this error (I am using zappa to upload).
libodbc.so.2: cannot open shared object file: No such file or directory: ImportErrorTraceback (most recent call last): File "/var/task/handler.py", line 609, in lambda_handler return LambdaHandler.lambda_handler(event, context) File "/var/task/handler.py", line 240, in lambda_handler handler = cls() File "/var/task/handler.py", line 134, in init self.app_module = importlib.import_module(self.settings.APP_MODULE) File "/var/lang/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/var/task/app.py", line 8, in
import pyodbc ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
I am using Python 3.6 and have the pyodbc installed in my virtual env and its working fine in EC2
My connection string is this:
app = Flask(__name__)
details = {
'server' : '*********ap-south-1.rds.amazonaws.com',
'database' : '*******',
'username' : '*****',
'password' : '*****'
}
params='DRIVER={{ODBC Driver 13 for SQL Server}};SERVER={server};PORT=1443; DATABASE={database};UID={username};PWD={password}'.format(**details)
params = urllib.parse.quote_plus(params)
app.config['SQLALCHEMY_DATABASE_URI'] = "mssql+pyodbc:///?odbc_connect=%s" % params
#######################
db = SQLAlchemy(app)
Is there any dependency like ODBC driver file that i need to place? Please Help