We have this unique integration which we are working out from AWS Lambda Function -> Oracle 11g RAC(On Prem).
We have chosen AWS Lambda with a runtime of node v8 and hence tried by default to use node-oracledb as the driver. There were many challenges to establish the connections when a fork of node-oracledb --> oracledb-for-lambda was able to make this work between a function within AWS to a simple oracle DB within AWS.
However the code broke with following error when tried out with original environment where it connects to an on-premise Oracle 11g RAC cluster. Following is the error:
ORA-21561: OID generation failed
VPC[{AWS Node Lambda}] -> Direct Connect -> On prem n/w -> Oracle RAC Cluster
Additional Notes:
Added HOSTALIASES file for name resolution
var oracledb = require('oracledb-for-lambda');
var os = require('os');
var fs = require('fs');
'use strict';
str_host = os.hostname() + ' localhost\n';
fs.writeFileSync(process.env.HOSTALIASES,str_host , function(err){
if(err) throw err;
});
var connAttr = {
user: "user",
password: "pass",
connectString: "connection string"
};
oracledb.getConnection(connAttr, function (err, connection) {
if (err) {
log.error("Error Log>>>>>: " + err.message);
return;
}
log.info('Connection was successful!' + connection);
connection.close(
function (err) {
if (err) {
log.error('Error while closing connection'+err.message);
return;
}
});
});
Make sure the connection string which you have give is in below format
//server-ip:port/database_name
Related
I'm using the snowflake node driver to connect to a DB. When running the connector from a local server I have no issues. However, when I try the same function running in lambda I can't seem to connect. There are no errors, exceptions, or timeouts... just nothing. Here is the code I'm using per their documentation.
var snowflake = require("snowflake-sdk");
var connection = snowflake.createConnection({
account: "****",
username: "******",
password: "******",
});
connect(connection);
const response = {
statusCode: 200,
body: JSON.stringify("Hello from Lambda!"),
};
return response;
function connect(connection) {
console.log("in connection");
let connection_ID;
try {
connection.connect(function (err, conn) {
if (err) {
console.error("Unable to connect: " + err);
} else {
console.log("Successfully connected to Snowflake");
// Optional: store the connection ID.
connection_ID = conn.getId();
}
console.log(connection_ID);
});
} catch (err) {
console.log(err);
}
}
For clarity, my lambda has no issues connecting to other API's, and is not running behind a VPC.
Any help would be greatly appreciated.
If you have not selected any VPC for your lambda function, it will use the default VPC of the region.
Can you select a VPC, which has access to the snowflake public endpoints and check.
If still an issue, please post the Cloud watch logs, it should give a clue.
You can also check on snowflake History page, if you get any Client-side connection request from the lambda or not.
I'm trying to implement a call back on NodeJS EC2 server that's interacting with AWS RDS Postgresql. I'm not quite sure how it's done. There seems to be a EventEmitter method within AWS-SDK's RDS module. It's designed for all RDS instance types like MySQL, Aurora, etc. Not specifically for postgres. All I'm trying to do is to get some kind of callback after an INSERT or DELETE query.
It is not specific if your postgres is RDS or standalone on EC2.
You will need
var pg = require('pg');
var dbe={"result":null};
function Q(sqlQuery,callback) {
/* async, vulnerable, simple */
var conString = "postgres://"+dbUser+":"+dbPass+"#"+dbHost+":"+dbPort+"/"+dbName+"?ssl=true";
pg.connect(conString, function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query(sqlQuery, function(err, result) {
done();//call `done()` to release the client back to the pool
if(err) {
return console.error('error running query', err);
}
dbe.result = result;
//console.log(JSON.parse(result.setEncoding('utf8');));
callback();
});
});
}
And calling
var res = Q('select now()', function(a) {console.log(dbe.result)});
or similar - I don't have a playground to test atm
Connecting to any DB with Java is very simple - I just need the appropriate JAR in the classpath. Alternatively, steps involved in installing any of the (example) Oracle drivers for NodeJS are very complicated (you need the windows sdk, visual studio, python 2.7, a whole bunch of environment variables). This leads me to think I'm missing something. Is there a simpler way to connect?
1. Connecting a SQL Database:
There are node modules which will help you connect to DB. Lets consider mysql as of now:
npm install mysql
Consider the mysql module. Please have a look at the documentation. From the Docs itself:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
2.Connecting a NoSQL Database:
Node.js really works well with NoSQL databases. If you are considering MongoDB,
npm install mongodb
Then try:
// Retrieve
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }
db.collection('test', function(err, collection) {});
db.collection('test', {w:1}, function(err, collection) {});
db.createCollection('test', function(err, collection) {});
db.createCollection('test', {w:1}, function(err, collection) {});
});
I have tried pg and other modules and packages to connect Redshift PostgreSQL through Node and Meteor.
This is my recent code written in node. It is unable to connect to Redshift. The client.connect function never responds.
But if I try to connect to some other PostgreSQL server, like localhost or some other remote server, then the code works as expected.
Same is the problem with Meteor.
var pg = require('pg');
var conString = "postgres://User:Password#EndPoint/Database";
//var conString = "postgres://postgres:postgres#localhost/postgres";
console.log("Started...");
var client = new pg.Client(conString);
console.log("Client", client);
client.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
client.query('SELECT NOW() AS "theTime"', function(err, result) {
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].theTime);
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
client.end();
});
});
console.log("End...");
I want to connect through Meteor. But if not possible through Meteor,
Node.js will also work.
I am using node v.0.10.33 couchbase, node module v.2.0.0 and couchbase-server-v.3.0.1
var couchbase = require("couchbase");
// Connect to Couchbase Server
var cluster = new couchbase.Cluster('10.50.10.31:8091');
var bucket = cluster.openBucket('beer-sample', function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// Retrieve a document
bucket.get('aass_brewery-juleol', function(err, result) {
if (err) {
// Failed to retrieve key
throw err;
}
var doc = result.value;
console.log(doc.name + ', ABV: ' + doc.abv);
// Store a document
doc.comment = "Random beer from Norway";
bucket.replace('aass_brewery-juleol', doc, function(err, result) {
if (err) {
// Failed to replace key
throw err;
}
console.log(result);
// Success!
process.exit(0);
});
});
});
when i run the above program on the same machine in which couchbase server is installed its working fine..
with this line
var cluster = new couchbase.Cluster('127.0.0.1:8091');
But when i run with another system which connected through Local area network I am getting network error. with this line
var cluster = new couchbase.Cluster('10.50.10.31:8091');
this error...
Couchbase Error : Network Failure
also tried
var cluster = new couchbase.Cluster('couchbase://10.50.10.31')
not working...
var cluster = new couchbase.Cluster('couchbase://localhost')
working fine...
Where i am going wrong please help me...
sorry for mistakes.
As per Couchbase Node.js SDK documentation, try creating connection like this:
var couchbase = require("couchbase");
var bucket = new couchbase.Connection({
'bucket':'beer-sample',
'host':'10.50.10.31:8091'
}, function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// your code to work with bucket here...
});
The problem is with python and node-gyp
i have upgraded python
and rebuild the couchbase module
cd path_to_nodejs_project/node_modules/coucbase/
node-gyp clean
node-gyp configure
node-gyp build
This solved my problem