我想使用无服务器功能查询数据库,因此我需要通过登陆节点ssh-tunnel来进行rds查询。
但是,这不起作用。有什么想法吗?
exports.handler = function(context, event, callback) {
const tunnel = require('tunnel-ssh');
const { Client } = require('pg');
const sshUserName = 'ec2user';
const sshPassword = 'EC2-pwd';
let sshConfig = {
host: 'ecx-xxx-xxx.compute-1.amazonaws.com',
port: 22,
username: sshUserName,
password: sshPassword,
keepaliveInterval: 60000,
keepAlive: true,
dstHost: 'some-name-for-db.us-east-1.rds.amazonaws.com',
dstPort: 5432
};
let dbConfig = {
host: 'some-name-for-db.us-east-1.rds.amazonaws.com',
port: 5334,
user: 'user',
password: 'some-password',
};
const tnl = tunnel(sshConfig, function (error, server) {
if (error) {
throw error;
}
const client = new Client(dbConfig);
// do something with db
});
};