I have a very simple Python I need to use as an AWS Lambda function:
import pyodbc
def lambda_handler():
cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
"Server=AAA;"
"Database=BBB;"
"UID=CCC;"
"PWD=DDD;")
cursor = cnxn.cursor()
cursor.execute("INSERT INTO [dbo].[log]([opened_by_id],[open_timestamp],[type_id],[title]) VALUES(118,GETDATE(),1,'test_1')")
cnxn.commit()
I've installed pyodbc using pip and have it as a folder where the py file is. both the py file and the pyodbc folder are added to a zip file that I've uploaded to Lambda functions Console. When I test the function I receive an error:
START RequestId: XXX Version: $LATEST
Unable to import module 'detect_last_sample': No module named 'pyodbc'
END RequestId: XXX
REPORT RequestId: YYY Duration: 1.24 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 21 MB
Please help me understand what am I missing here. Many thanks!
--EDIT Looks like there's more to this issue then simply creating a zip with the external libs, there is an issue with pyodbc itself when used in aws lambda. Anyway during my searches I found this repo containing pre complied libraries including pyodbc : https://github.com/Miserlou/lambda-packages
Good luck to all.