I have an Aurora Serverless db cluster running MySQL. I'm trying to write an application that takes a string from a script and puts it onto the database.
I've been able to successfully connect to the cluster using my ec2 in PuTTY, a node program on the ec2, and MySQL Workbench, but I haven't been able to with my own code. I'm trying to use the node modules ssh2 and mysql2.
var mysql = require('mysql2');
var Client = require('ssh2').Client;
var ssh = new Client();
ssh.on('ready', function() {
ssh.forwardOut(
'127.0.0.1',
12345,
'127.0.0.1',
3306,
function (err, stream) {
if (err) throw err;
var sql = mysql.createConnection({
host: 'my db endpoint',
user: 'root',
password: 'pass',
database: 'testdb',
stream: stream
//sql stuff
});
}).connect({
host: 'ec2-publicdns',
port: '22',
username: 'ec2-user',
privateKey: require('fs').readFileSync('pkeyssh') //pem key converted to openssh using PuTTYgen
});
When I run this, I get: Error: (SSH) Channel open failure: Connection refused
Also, is Aurora serverless the correct solution for me? It seems as if there isn't a way to really talk to it without going through the ec2. Should I be looking for a different database host?
127.0.0.1
to your db endpoint, and them changehost: 'my db endpoint'
tohost: '127.0.0.1'
. – Universally