ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

Getting licensing problem SQL1598N, Nodejs script running on AWS-Lambda #931

Closed SunnyRajdeep-V42386 closed 11 months ago

SunnyRajdeep-V42386 commented 1 year ago

Please provide below information while opening an issue to understand your problem

For non-Windows system, output of below commands from terminal:

node -v : 14.18.1 npm ls ibm_db db2level echo $IBM_DB_HOME: none echo $PATH: none echo $LD_LIBRARY_PATH $DYLD_LIBRARY_PATH: none

Please provide below problem specific info:

=========================================

For Connection related issue

  1. Connection string: DATABASE=${DB_CONFIG.database};HOSTNAME=${DB_CONFIG.hostname};PORT=${DB_CONFIG.port};PROTOCOL=TCPIP;UID=${DB_CONFIG.id};PWD=${DB_CONFIG.password};
  2. For non-SSL connection, update connection info for db2cli validate command in file ibm_db/installer/testODBCConnection.bat for windows or ibm_db/installer/testODBCConnection.sh for non-Windows. Then execute testODBCConnection.bat from Administrator command prompt on Windows or testODBCConnection.sh script from terminal on non-Windows and share complete output of script along will all generated 1.* files in zip file.
  3. Complete output of db2cli validate command.
  4. Output ==================================================

    Client information for the current copy:

    Client Package Type : IBM Data Server Driver For ODBC and CLI Client Version (level/bit): DB2 v11.5.6.0 (special_13806/64-bit) Client Platform : Linux/X8664 Install/Instance Path : /app/node_modules/ibm_db/installer/clidriver DB2DSDRIVER_CFG_PATH value: db2dsdriver.cfg Path : /app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg DB2CLIINIPATH value : db2cli.ini Path : /app/node_modules/ibm_db/installer/clidriver/cfg/db2cli.ini db2diag.log Path : /app/node_modules/ibm_db/installer/clidriver/db2dump/db2diag.log

    db2dsdriver.cfg schema validation for the entire file:

    Note: The validation utility could not find the configuration file db2dsdriver.cfg. The file is searched at "/app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg".

    db2cli.ini validation for database "XXXX:subdomain.domain.com:5011":

    Note: The validation utility could not find the configuration file db2cli.ini. The file is searched at "/app/node_modules/ibm_db/installer/clidriver/cfg/db2cli.ini".

    db2dsdriver.cfg validation for database "XXXX:subdomain.domain.com:5011":

    Note: The validation utility could not find the configuration file db2dsdriver.cfg. The file is searched at "/app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg".

    Connection attempt for database "XXXX:subdomain.domain.com:5011":

    [FAILED]: [IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968

    Valid License Found : No License location : N/A Server routine type attempted : SP and UDF DB2 connect license version : N/A

    Error: The validation operation failed.

    ========================================= The validation is completed.

    ./node_modules/ibm_db/installer/testODBCConnection.sh: 6: [: unexpected operator ./node_modules/ibm_db/installer/testODBCConnection.sh: 13: [: Linux: unexpected operator ./node_modules/ibm_db/installer/testODBCConnection.sh: 21: [: Linux: unexpected operator Could not create the trace file "1.trc". ./node_modules/ibm_db/installer/testODBCConnection.sh: 34: [: Linux: unexpected operator Trace is already off; no action was taken. Could not create file "1.flw". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.fmt". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.fmtc". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.cli". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. exec error: Error: Command failed: sh ./node_modules/ibm_db/installer/testODBCConnection.sh ./node_modules/ibm_db/installer/testODBCConnection.sh: 6: [: unexpected operator ./node_modules/ibm_db/installer/testODBCConnection.sh: 13: [: Linux: unexpected operator ./node_modules/ibm_db/installer/testODBCConnection.sh: 21: [: Linux: unexpected operator Could not create the trace file "1.trc". ./node_modules/ibm_db/installer/testODBCConnection.sh: 34: [: Linux: unexpected operator Trace is already off; no action was taken. Could not create file "1.flw". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.fmt". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.fmtc". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. Could not create file "1.cli". Check that you have enough disk space and have permission to create a file. Another Possible reason might be too many open files Try using [ulimit -n <# of files>] to increase the maximum number of open files. START RequestId: 836b4337-afd8-4274-817e-7602a3958faa Version: $LATEST RequestId: 836b4337-afd8-4274-817e-7602a3958faa Error: Runtime exited without providing a reason Runtime.ExitError

--> ./node_modules/ibm_db/installer/clidriver/license - folder containts

UNIX db2consv_zs.lic odbc_REDIST.txt odbc_notices.txt ----> ./tmp // tried copying license file under lambda temp(tmp) folder db2consv_zs.lic

[Error: [IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968 ] { error: '[ibm_db] SQL_ERROR', sqlcode: -1598, state: '42968' } { success: -3, message: { message: 'Connection not open.', sqlstate: '08001', sqlcode: -30081 } }

For SQL1598N Error

RUN apt-get install -y apt-transport-https make gcc g++ RUN pip install --no-cache --upgrade pip setuptools

FROM artifactory.aws.aflac.com/docker/node:14.18.1 RUN dir -s

COPY * app/ WORKDIR /app

RUN npm install --unsafe-perm ibm_db -clidriver=v11.5.6

RUN rm ./node_modules/ibm_db/installer/testODBCConnection.sh RUN cp testODBCConnection.sh ./node_modules/ibm_db/installer/ RUN cd ./node_modules/ibm_db/installer/clidriver/cfgcache/ && ls -al && rm conlic.bin

RUN dir -s RUN chmod -R 775 . RUN cp db2consv_zs.lic ./node_modules/ibm_db/installer/clidriver/license/

RUN cd ./node_modules/ibm_db/installer/clidriver/license/ && ls -ltra

ENTRYPOINT [ "node", "index.js" ]


### Code:

const { exec } = require('child_process'); var yourscript = exec('sh ./node_modules/ibm_db/installer/testODBCConnection.sh', (error, stdout, stderr) => { console.log(stdout); console.log(stderr); if (error !== null) { console.log(exec error: ${error}); } });

let connStr = DATABASE=${DB_CONFIG.database};HOSTNAME=${DB_CONFIG.hostname};PORT=${DB_CONFIG.port};PROTOCOL=TCPIP;UID=${DB_CONFIG.id};PWD=${DB_CONFIG.password};;

(async (key, location) => {

await fs.copyFile("./db2consv_zs.lic", "/tmp/db2consv_zs.lic", (err)=>{ if(err) console.log("File was not copied to destination folder", err); }); console.log("----> ./node_modules/ibm_db/installer/clidriver/license"); await fs.readdirSync("./node_modules/ibm_db/installer/clidriver/license").forEach(file => { console.log(file); }); console.log("----> ./tmp"); await fs.readdirSync("/tmp").forEach(file => { console.log(file); });

ibmDb.open(connStr, function (err, conn) {
  if (err) {
    console.log(err);
  }

  const query =
    `SELECT 'Region' AS "TYPE",REGN.REGN_REGION_CD AS "CODE",REGN.REGN_REGION_DSC AS "DESCRIPTION",REGN.COMP_COMPANY_NO AS "OTHER",REGN.REGN_STD_CONTRACT_CD AS "STD_CONTRACT" FROM PCLADB01.TBL_LA_REGION REGN WITH UR`;

  conn.query(query, function (err, data2) {
    if (err) {
      console.log({ success: -3, message: err });
    }
    conn.close(function () {
      console.log(data2);
    });
  });
})

})();



Can you Please help me to resolve this issue.
Is it file write permission issue on AWS-Lambda?
Is there any specific license file needed for AWS lambda - Linux os?
License file containts:
![image](https://github.com/ibmdb/node-ibm_db/assets/122006873/e36c1586-f40d-4008-a779-4cddc6e45e11)
bimalkjha commented 1 year ago

@SunnyRajdeep-V42386 It seems the user which is running app do not have permission to create a file under "/app/node_modules/ibm_db/installer/clidriver/license directory. Please check the permission of each directory starting from /app till license. It should have 755 permission. The ibm_db should be installed by same user who runs app, else change permission of license directory to 775 and try. Thanks.

bimalkjha commented 1 year ago

Note that during the connection, clidriver reads file license/db2consv_zs.lic and try to create nodelock files under license directory. It seems, user do not have sufficient permission to create a file under license directory and hence error. Please check the permissions. Alternatively, you can install ibm-db using below commands and try:

cd $HOME
wget https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/v11.5.6/linuxx64_odbc_cli.tar.gz
tar xzf linuxx64_odbc_cli.tar.gz
cp db2consv_zs.lic clidriver/license
export IBM_DB_HOME=$HOME/clidriver
cd /app
npm install ibm_db
node app.js

Thanks.

SunnyRajdeep-V42386 commented 1 year ago

@bimalkjha My index.js and node modules residing in:root/app/ and /tmp folder is residing at /root/tmp where lambda have write permission. I am trying to copy root/app/node_modules/ibm_db/installer folder to /root/tmp, so trying to achieve following things:

To achieve both, could you suggest what environment and Path variables and their values needs to be set for the linux oS/Lambda

I am trying to follow issue #616.

bimalkjha commented 1 year ago

@SunnyRajdeep-V42386 You can run below commands and verify:

mv /root/app/node_modules/ibm_db/installer /tmp
cp db2consv_zs.lic /tmp/installer/clidriver/license
export IBM_DB_HOME=/tmp/installer/clidriver
export PATH=/tmp/installer/clidriver/bin:/tmp/installer/clidriver/lib:$PATH
export LD_LIBRARY_PATH=/tmp/installer/clidriver/lib
cd /root/app
rm -rf node_modules/ibm_db
npm install ibm_db

Thanks.

SunnyRajdeep-V42386 commented 1 year ago

@bimalkjha As I am using docker image and docker commands I altered flow of suggested execution as below

RUN export IBM_DB_HOME=/tmp/installer/clidriver
RUN export PATH=/tmp/installer/clidriver/bin:/tmp/installer/clidriver/lib:$PATH
RUN export LD_LIBRARY_PATH=/tmp/installer/clidriver/lib
#RUN cd /root/app
RUN rm -rf ./node_modules/ibm_db
RUN npm install --unsafe-perm ibm_db
RUN mv ./node_modules/ibm_db/installer /tmp
RUN cp db2consv_zs.lic /tmp/installer/clidriver/license

After running nodejs script getting following error

/app/node_modules/bindings/bindings.js:121
--
throw e;
^
Error: libdb2.so.1: cannot open shared object file: No such file or directory
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at bindings (/app/node_modules/bindings/bindings.js:112:48)
at Object.<anonymous> (/app/node_modules/ibm_db/lib/odbc.js:57:31)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32) {
code: 'ERR_DLOPEN_FAILED'
}
bimalkjha commented 1 year ago

@SunnyRajdeep-V42386 The error is due to change in the flow of suggested command. libdb2.so.1 is under ibm_db/installer/clidriver/lib directory. Since, you moved this library post install, hence error at runtime. Reinstalling ibm_db again should fix the problem.

Update your docker file as below and verify:

RUN cd /root/app
RUN npm install --unsafe-perm ibm_db
RUN mv ./node_modules/ibm_db/installer /tmp
RUN cp db2consv_zs.lic /tmp/installer/clidriver/license
RUN export IBM_DB_HOME=/tmp/installer/clidriver
RUN export PATH=/tmp/installer/clidriver/bin:/tmp/installer/clidriver/lib:$PATH
RUN export LD_LIBRARY_PATH=/tmp/installer/clidriver/lib
RUN rm -rf ./node_modules/ibm_db
RUN npm install --unsafe-perm ibm_db

Thanks.

bimalkjha commented 1 year ago

Note that once you export IBM_DB_HOME=/tmp/installer/clidriver, reinstalling ibm_db will not download clidriver and you'll not get installer/clidriver in second install. Thanks.

bimalkjha commented 1 year ago

Here, first npm install --unsafe-perm ibm_db is to get clidriver directory. Instead you can directly download clidriver too. In that case the commands would be like below:

RUN mkdir /tmp/installer && cd /tmp/installer
RUN wget https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz
RUN tar xzf linuxx64_odbc_cli.tar.gz
RUN cp db2consv_zs.lic /tmp/installer/clidriver/license
RUN export IBM_DB_HOME=/tmp/installer/clidriver
RUN export PATH=/tmp/installer/clidriver/bin:/tmp/installer/clidriver/lib:$PATH
RUN export LD_LIBRARY_PATH=/tmp/installer/clidriver/lib
RUN cd /root/app
RUN rm -rf ./node_modules/ibm_db
RUN npm install --unsafe-perm ibm_db
RUN cp ./node_modules/ibm_db/installer/testODBCConnection.sh /tmp/installer

Thanks.

SunnyRajdeep-V42386 commented 1 year ago

@bimalkjha We are trying to copy files into /tmp folder upfront in docker file but when we deploy code to lambda, lambda clear out the /tmp directory everytime. I got reference here too: https://stackoverflow.com/questions/48580673/how-to-access-file-in-tmp-directory-of-aws-lambda#answer-73642693

On other side I tried to copy /ibm_db/installer in /tmp on run time and ran testODBCConnection.sh: given me following result: Even we are setting IBM_DB_HOME and LD_LIBRARY_PATH it seems its not picking up those path in lambda. I tried to change IBM_DB_HOME in testODBCConnection.sh as below: image

============================================================================
Client information for the current copy:
===============================================================================
Client Package Type       : IBM Data Server Driver For ODBC and CLI
Client Version (level/bit): DB2 v11.5.8.0 (special_26260/64-bit)
Client Platform           : Linux/X8664
Install/Instance Path     : /app/node_modules/ibm_db/installer/clidriver
DB2DSDRIVER_CFG_PATH value: <not-set>
db2dsdriver.cfg Path      : /app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg
DB2CLIINIPATH value       : <not-set>
db2cli.ini Path           : /app/node_modules/ibm_db/installer/clidriver/cfg/db2cli.ini
db2diag.log Path          : /app/node_modules/ibm_db/installer/clidriver/db2dump/db2diag.log
===============================================================================
db2dsdriver.cfg schema validation for the entire file:
===============================================================================
Note: The validation utility could not find the configuration file
db2dsdriver.cfg. The file is searched at
"/app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg".
===============================================================================
db2cli.ini validation for database "xxx:upico.xxx.com:5011":
===============================================================================
Note: The validation utility could not find the configuration file db2cli.ini.
The file is searched at
"/app/node_modules/ibm_db/installer/clidriver/cfg/db2cli.ini".
===============================================================================
db2dsdriver.cfg validation for database "xxx:upico.xxx.com:5011":
===============================================================================
Note: The validation utility could not find the configuration file
db2dsdriver.cfg. The file is searched at
"/app/node_modules/ibm_db/installer/clidriver/cfg/db2dsdriver.cfg".
===============================================================================
Connection attempt for database "xxx:upico.xxx.com:5011":
===============================================================================
[FAILED]: [IBM][CLI Driver] SQL1598N  An attempt to connect to the database server failed because of a licensing problem.  SQLSTATE=42968
===============================================================================
Valid License Found            : No
License location               : N/A
Server routine type attempted  : SP and UDF
DB2 connect license version    : N/A
===============================================================================
Error: The validation operation failed.
===============================================================================
===============================================================================
The validation is completed.
===============================================================================
/tmp/installer/testODBCConnection.sh: 6: [: unexpected operator
/tmp/installer/testODBCConnection.sh: 13: [: Linux: unexpected operator
/tmp/installer/testODBCConnection.sh: 21: [: Linux: unexpected operator
Could not create the trace file "1.trc".
/tmp/installer/testODBCConnection.sh: 34: [: Linux: unexpected operator
Trace is already off; no action was taken.
Could not create file "1.flw".
Check that you have enough disk space and have permission to create a file.
Another Possible reason might be too many open files
Try using [ulimit -n <# of files>] to increase the maximum number of open files.
Could not create file "1.fmt".
Check that you have enough disk space and have permission to create a file.
Another Possible reason might be too many open files
Try using [ulimit -n <# of files>] to increase the maximum number of open files.
Could not create file "1.fmtc".
Check that you have enough disk space and have permission to create a file.
Another Possible reason might be too many open files
Try using [ulimit -n <# of files>] to increase the maximum number of open files.
Could not create file "1.cli".
Check that you have enough disk space and have permission to create a file.
Another Possible reason might be too many open files
Try using [ulimit -n <# of files>] to increase the maximum number of open files.
Error: Command failed: sh /tmp/installer/testODBCConnection.sh

Thanks.

bimalkjha commented 1 year ago

@SunnyRajdeep-V42386 See the result of testODBCConnection.sh script. The clidriver is still getting picked up from Install/Instance Path : /app/node_modules/ibm_db/installer/clidriver and not from /tmp/intaller. Check some other config file which might have setting clidriver at old location. Also, you need to set IBM_DB_HOME first and then install ibm_db. If it is reinstallation, then ibm_db too has not found IBM_DB_HOME set during installation time. Also, why you need to copy installer under /tmp only? Can't you copy it under /home/$USER directory? Actually, there is no requirement to copy installer under /tmp; but you need to check why the user who runs app, do not have write permission under /app/node_modules/ibm_db/installer/clidriver/license directory? If you can't give permission then you must need to set IBM_DB_HOME before installation of ibm_db so that clidriver can't get downloaded under ibm_db/installer. Thanks.

bimalkjha commented 1 year ago

About error in execution of testODBCConnection.sh, use Korn Shell (ksh) and then run it. Script works with ksh. Thanks.

SunnyRajdeep-V42386 commented 1 year ago

Hi @bimalkjha we managed to run testODBCConnection.sh from /temp/installer folder Now I am getting following message:

2023-07-06T09:08:51.682Z    d5b75ba4-0547-4661-8929-2fb23aec9ac8    INFO    /tmp/installer/clidriver

===============================================================================
Client information for the current copy:
===============================================================================

Client Package Type       : IBM Data Server Driver For ODBC and CLI
Client Version (level/bit): DB2 v11.5.8.0 (special_26260/64-bit)
Client Platform           : Linux/X8664
Install/Instance Path     : /tmp/installer/clidriver
DB2DSDRIVER_CFG_PATH value: <not-set>
db2dsdriver.cfg Path      : /tmp/installer/clidriver/cfg/db2dsdriver.cfg
DB2CLIINIPATH value       : <not-set>
db2cli.ini Path           : /tmp/installer/clidriver/cfg/db2cli.ini
db2diag.log Path          : /tmp/installer/clidriver/db2dump/db2diag.log

===============================================================================
db2dsdriver.cfg schema validation for the entire file:
===============================================================================

Note: The validation utility could not find the configuration file 
db2dsdriver.cfg. The file is searched at 
"/tmp/installer/clidriver/cfg/db2dsdriver.cfg".

===============================================================================
db2cli.ini validation for database "xxx:upico.xxx.com:5011":
===============================================================================

Note: The validation utility could not find the configuration file db2cli.ini. 
The file is searched at "/tmp/installer/clidriver/cfg/db2cli.ini".

===============================================================================
db2dsdriver.cfg validation for database "xxx:upico.xx.com:5011":
===============================================================================

Note: The validation utility could not find the configuration file 
db2dsdriver.cfg. The file is searched at 
"/tmp/installer/clidriver/cfg/db2dsdriver.cfg".

===============================================================================
Connection attempt for database "xxx:upico.xxx.com:5011":
===============================================================================

[SUCCESS]

===============================================================================

Valid License Found            : Yes
License location               : Client
Server routine type attempted  : SP and UDF
DB2 connect license version    : N/A
===============================================================================
The validation is completed.
===============================================================================

total 17M
-rw-r--r-- 1 sbx_user1051 990  67K Jul  6 09:08 APIDocumentation.md
-rw-r--r-- 1 sbx_user1051 990 1.2K Jul  6 09:08 LICENSE
-rw-r--r-- 1 sbx_user1051 990  15K Jul  6 09:08 INSTALL.md
-rw-r--r-- 1 sbx_user1051 990  28K Jul  6 09:08 CHANGES.md
-rw-r--r-- 1 sbx_user1051 990  25K Jul  6 09:08 README.md
-rw-r--r-- 1 sbx_user1051 990 3.4K Jul  6 09:08 binding.gyp
-rw-r--r-- 1 sbx_user1051 990   26 Jul  6 09:08 _config.yml
drwxr-xr-x 2 sbx_user1051 990 4.0K Jul  6 09:08 contributing
drwxr-xr-x 3 sbx_user1051 990 4.0K Jul  6 09:08 build
drwxr-xr-x 2 sbx_user1051 990 4.0K Jul  6 09:08 examples
drwxr-xr-x 2 sbx_user1051 990 4.0K Jul  6 09:08 lib
drwxrwxr-x 3 sbx_user1051 990 4.0K Jul  6 09:08 installer
drwxr-xr-x 5 sbx_user1051 990 4.0K Jul  6 09:08 node_modules
-rw-r--r-- 1 sbx_user1051 990 1.9K Jul  6 09:08 package.json
drwxr-xr-x 2 sbx_user1051 990 4.0K Jul  6 09:08 src
drwxr-xr-x 4 sbx_user1051 990 4.0K Jul  6 09:08 test
-rw------- 1 sbx_user1051 990 4.5M Jul  6 09:08 1.trc
-rw-r----- 1 sbx_user1051 990 3.0M Jul  6 09:08 1.flw
-rw-r----- 1 sbx_user1051 990 9.1M Jul  6 09:08 1.fmt
-rw-r----- 1 sbx_user1051 990  54K Jul  6 09:08 1.fmtc
-rw-r----- 1 sbx_user1051 990 4.5K Jul  6 09:08 1.cli
total 60K
-rwxrwxr-x  1 sbx_user1051 990  517 Jul  6 09:08 setenv.sh
-rwxrwxr-x  1 sbx_user1051 990  853 Jul  6 09:08 ifx.sh
-rwxrwxr-x  1 sbx_user1051 990  37K Jul  6 09:08 driverInstall.js
-rw-r--r--  1 sbx_user1051 990 1.2K Jul  6 09:08 testODBCConnection.sh
-rwxrwxr-x  1 sbx_user1051 990  903 Jul  6 09:08 testODBCConnection.bat
drwxrwxr-x 15 sbx_user1051 990 4.0K Jul  6 09:08 clidriver

2023-07-06T09:08:51.682Z    d5b75ba4-0547-4661-8929-2fb23aec9ac8    INFO    /tmp/installer/testODBCConnection.sh: 6: [: /tmp/installer/clidriver: unexpected operator
/tmp/installer/testODBCConnection.sh: 13: [: Linux: unexpected operator
/tmp/installer/testODBCConnection.sh: 21: [: Linux: unexpected operator
Trace is turned on
/tmp/installer/testODBCConnection.sh: 36: [: Linux: unexpected operator
Trace is turned off
Total number of trace records     : 35367
Trace truncated                   : NO
Trace wrapped                     : NO
Number of trace records formatted : 2 (pid: 24 tid 140031771225024 node: -1) 
Number of trace records formatted : 35210 (pid: 28 tid 140351312694208 node: -1) 
Trace truncated                   : NO
Trace wrapped                     : NO
Total number of trace records     : 35367
Number of trace records formatted : 35212
Trace truncated                   : NO
Trace wrapped                     : NO
Total number of trace records     : 35367
Number of trace records formatted : 32
Trace truncated                   : NO
Trace wrapped                     : NO
Total number of trace records     : 35367
Number of trace records formatted : 155

Getting this error too: [Error: [IBM][CLI Driver] SQL1598N An attempt to connect to the database server failed because of a licensing problem. SQLSTATE=42968 ] { error: '[ibm_db] SQL_ERROR', sqlcode: -1598, state: '42968' }

{

success: -3, message: { message: 'Connection not open.', sqlstate: '08001', sqlcode: -30081 } }

bimalkjha commented 1 year ago

@SunnyRajdeep-V42386 Now the output of testODBCConnection.sh file looks good and it is able to connect to server. We can see the SUCCESS message with below info and there is no more SQL1598N error with it.

Valid License Found            : Yes
License location               : Client
Server routine type attempted  : SP and UDF
DB2 connect license version    : N/A

So, how are you able to get SQL1598N error and using which script? Please update the database connection info in ibm_db/test/config.testConnectionStrings.json file same as you used in testODBCConnection.sh and then execute node test/test-basic-test.js script. Share the complete output of test-basic-test.js here. Thanks.

SunnyRajdeep-V42386 commented 12 months ago

@bimalkjha Sorry for late response, if we use /tmp directory for aws-lambda it is working. I added these environment variables in Lambda configuration: image

But for a AWS Lambda, Its time consuming to perform those initial operation to move ibm_db node-modules to /tmp directory and do the connection.

Thanks for all the support.

Sharing below Dockerfile who is trying for it on Linux / Aws-Lambda:

FROM python:3.7
RUN pip install --no-cache --upgrade pip setuptools 

# Define custom function directory
ARG FUNCTION_DIR="app"

FROM node:16

# Include global arg in this stage of the build
ARG FUNCTION_DIR

# Install build dependencies
RUN apt-get update 
RUN apt-get install -y \
    gcc \
    g++ \
    make \
    cmake \
    unzip \
    libcurl4-openssl-dev

RUN dir -s
RUN cd /usr && ls -al

# Copy function code
#RUN mkdir -p ${FUNCTION_DIR}
COPY * app/

WORKDIR /app

# clearing cache if any 
RUN rm -rf ./node_modules/ibm_db

# Install Node.js dependencies
RUN npm install

# Install Node-ibm_db dependencies
RUN npm install --unsafe-perm ibm_db

# Copying .lic file to license folder
RUN cp db2consv_zs.lic ./node_modules/ibm_db/installer/clidriver/license/

# Updating file permissions of all files
RUN chmod -R 775 ./node_modules/ibm_db/installer 

# Replacing packaged testODBCConnection.sh with valid credentials to installer, this contains only valid credentials connection string. Not a mandatory step.
RUN rm ./node_modules/ibm_db/installer/testODBCConnection.sh
RUN cp testODBCConnection.sh ./node_modules/ibm_db/installer/
RUN cd ./node_modules/ibm_db/installer/clidriver/cfgcache/ && ls -al && rm conlic.bin

# Install the runtime interface client
RUN npm install aws-lambda-ric

# Grab a fresh slim copy of the image to reduce the final size
# FROM node:18-buster-slim

# Required for Node runtimes which use npm@8.6.0+ because
# by default npm writes logs under /home/.npm and Lambda fs is read-only
ENV NPM_CONFIG_CACHE=/tmp/.npm

# Set runtime interface client as default command for the container runtime
ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-ric"]
# Pass the name of the function handler as an argument to the runtime
CMD ["app.handler"]

In your script you need to move /app/node_modules/ibm_db/ all folder contents to /tmp folder const srcDir = "/app/node_modules/ibm_db"; const destDir = "/tmp";

bimalkjha commented 11 months ago

@SunnyRajdeep-V42386 We are moving ibm_db/installer to /tmp so that the current user can have write permission for directory /tmp/installer/clidriver/license. If you could give write permission for current user for all dirs of /app/node_modules/ibm_db/installer/clidriver/license or change permissions to 775, then you need not to move ibm_db to /tmp and app will work smoothly. Its all about write permission. Or run the app as root user in aws lambda. All workarounds that we are doing is to give permission. Can we close this issue now as there is no problem with ibm_db but permission issue with your application environment? ibm_db is working fine when given correct permission to it. Thanks.

bimalkjha commented 11 months ago

Try to use EFS with lambda and see if it can make any change. Few users updated that - Was able to get this working using EFS and having the required dependency libraries.

bimalkjha commented 11 months ago

Closing the issue as using /tmp directory for aws-lambda is working as per last update. Thanks.