ibm_db.connect in AWS Lambda functions

920 views
Skip to first unread message

Leo

unread,
Aug 31, 2017, 11:17:34 PM8/31/17
to ibm_db
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!  

Craig Carpenter

unread,
Feb 19, 2018, 7:49:05 AM2/19/18
to ibm_db
Did you get a solution to this? This sounds very similar to what I just posted about -- hangs on the connect call. We have the IBM i Access ODBC Driver (64 bit) installed on RHEL 7.x -- AWS

Thanks

Saba Kauser

unread,
Feb 19, 2018, 8:07:36 AM2/19/18
to ibm_db
Leo,
Is the port correctly configured to listen for drda connection requests from client?

can you also share db2 traces for your problem.

cd clidriver/adm
db2trc on -f trc.dmp
<run your app, when hang is seen turn db2trc off from another window>
db2trc off
db2trc flw trc.dmp trc.flw
db2trc fmt trc.dmp trc.fmt
db2trc fmt -c trc.dmp trc,fmtc

and share trc.flw, trc.fmt and trc.fmtc files.

Thanks,
Saba.
Reply all
Reply to author
Forward
0 new messages