I am trying to create a simple Lambda function to query the msdb
of AWS RDS SQL server to monitor for failed jobs. I downloaded the python module pyodbc from https://github.com/Miserlou/lambda-packages/tree/master/lambda_packages/pyodbc
changed the file type from .tar.gz to zip and extracted the two file libodbc.so.2 and pyodbc.so I then put the two files in a zip folder structured like this
pythonjob.zip\python\lib\python3.7\site-packages\pyodbc
and in pyodbc
exists libodbc.so.2
and pyodbc.so
I then uploaded the pythonjob.zip
file on Lambda Layer and tested my script
import pyodbc
print(dir(pyodbc))
#ConnectionValues
endpoint = 'myservername.us-east-2.rds.amazonaws.com'
username = 'username'
password = 'password'
database_name = 'msdb'
conn = pyodbc.Connect( server= endpoint, user= username, password=password, database= database_name)
However I am getting the error [ERROR] AttributeError: module 'pyodbc' has no attribute 'Connect'
and the print(dir(pyodbc)) prints ['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
I am not sure what to do now. Your help is appreciated. Thank You!
@Esu Please change the connection statement to below:
conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+endpoint+';DATABASE='+database_name+';UID='+username+';PWD='+ password)
Also, The lambda layer which you're using doesn't contain the required packages. You can download the file from the below link, upload zip to the lambda layer and try the connection again.
Hope it works.