I'm having a problem with getting a time out when I run my Lambda function written in python to connect to my DB2 database on my EC2 instance.
I can connect to the database locally and remotely successfully.
My python script works when it's run on a server. It's only when hangs and times out whenever I issue the ibm_db.connect statement. I have the timeout value currently set to 4 seconds. Hung here for up to 60 seconds with the same result.
This is the error message.
START RequestId: : $LATEST
starting to process
in the try block
DRIVER={IBM DB2 ODBC DRIVER};DATABASE=sample;HOSTNAME=MyIPAddress;PORT=MyPort;PROTOCOL=TCPIP;UID=user;PWD=password;REPORT RequestId: Duration: 4001.00 ms Billed Duration: 4000 ms Memory Size: 128 MB Max Memory Used: 24 MB
2017-08-31T23:03:58.293Z Task timed out after 4.00 seconds
I have included the odbc_cli folder in my zip deployment file and I used pip to install ibm_db in my virtualenv environment. I also set the environmental variable LD_LIBRARY_PATH = odbc_cli/clidriver/lib. I was getting a different error before I set that.
My function looks like this: ( the parm1 and parm2 parameters are not used in this example, they are just there for testing )
from __future__ import print_function
import ibm_db
def dbinvk ( parm1, parm2) :
# This prints
print("starting to process")
# Perform a database connection
try:
# And this prints
print( "in the try block" )
dsn="DRIVER={IBM DB2 ODBC DRIVER};DATABASE=sample;HOSTNAME=MyIPAddress;PORT=MyPort;PROTOCOL=TCPIP;UID=user;PWD=password;"
# This prints too
print (dsn)
# conn= ibm_db.connect( "DATABASE=sample;HOSTNAME=MyIPAddress;PORT=MyPort;PROTOCOL=TCPIP;UID=user;PWD=password;", "", "")
# Code hangs here.......
conn=ibm_db.connect(dsn,"","")
# This never prints
print ( "set conn" )
except:
# noconn=ibm_db.conn_errormsg()
print(noconn)
print ( "in the except block" )
else:
print ( "in the else block" )
print ("The connection was successful.")
# Turn autocommit OFF
ibm_db.autocommit(conn, ibm_db.SQL_AUTOCOMMIT_OFF)
# These 4 lines print the current timestamp
SQL = "values current timestamp "
stmt = ibm_db.exec_immediate(conn, SQL)
ibm_db.fetch_row(stmt)
result=ibm_db.result(stmt,0)
print(result)
return result
# end script
Any ideas are appreciated!