PG通过ec2实例通过SSH隧道连接到RDS

时间:2019-05-25 17:58:33

标签: node.js postgresql pg http-tunneling

我想使用无服务器功能查询数据库,因此我需要通过登陆节点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
    });
};

0 个答案:

没有答案
相关问题