const ibmdb = require('ibm_db');
exports.handler = async (event) => {
// Extract the required input parameters from the Lambda event or context
const { database, hostname, uid, pwd, port, security, protocol, tableName } = event;
// Construct the connection string based on the provided parameters
const connString = `DATABASE=${database};HOSTNAME=${hostname};UID=${uid};PWD=${pwd};PORT=${port};SECURITY=${security};PROTOCOL=${protocol}`;
// Create a Lambda function that connects to the database, executes a query, and closes the connection
return new Promise((resolve, reject) => {
ibmdb.open(connString, (err, conn) => {
if (err) {
console.error('Error connecting to the database:', err);
reject(err);
return;
}
// Database connection is successful, you can now execute SQL queries
const selectQuery = `SELECT * FROM ${tableName}`; // Use the provided table name in the SQL query
conn.query(selectQuery, (err, rows) => {
if (err) {
console.error('Error executing query:', err);
reject(err);
} else {
console.log('Query result:', rows);
resolve(rows);
}
// Close the connection
conn.close((err) => {
if (err) {
console.error('Error closing the connection:', err);
}
});
});
});
});
};
For the above code i am getting below error
{
"errorType": "Error",
"errorMessage": "/var/task/node_modules/ibm_db/build/Release/odbc_bindings.node: invalid ELF header",
"trace": [
"Error: /var/task/node_modules/ibm_db/build/Release/odbc_bindings.node: invalid ELF header",
" at Module._extensions..node (node:internal/modules/cjs/loader:1340:18)",
" at Module.load (node:internal/modules/cjs/loader:1119:32)",
" at Module._load (node:internal/modules/cjs/loader:960:12)",
" at Module.require (node:internal/modules/cjs/loader:1143:19)",
" at require (node:internal/modules/cjs/helpers:121:18)",
" at bindings (/var/task/node_modules/bindings/bindings.js:112:48)",
" at Object.<anonymous> (/var/task/node_modules/ibm_db/lib/odbc.js:57:31)",
" at Module._compile (node:internal/modules/cjs/loader:1256:14)",
" at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)",
" at Module.load (node:internal/modules/cjs/loader:1119:32)"
]
}
I am trying the below code in AWS lambda.
package.json dependencies "dependencies": { "ibm_db": "^3.2.2" }
Please suggest what could be the issue and solution for this.
Thanks