Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement