1

I have made a DocumentDb cluster in AWS and was trying to connect with it my local server on my machine. This is my code

    const mongoose = require('mongoose')
const fs = require('fs');
mongoose.Promise = global.Promise
var ca = [fs.readFileSync(__dirname+'\\rds-combined-ca-bundle.pem')];

const url = 'mongodb://**********:*****************@docdb-2019-07-30-08-45-53.cluster-czognfvnmvja.us-east-1.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0'

mongoose.connect(url, {
    sslValidate: false,
    sslCA: ca,
    ssl:true,
    useNewUrlParser: true
}).then(() => {
    console.log("Connection Successfull")
}).catch((err) => {
    console.log("Error " + err);
})
  • Is it possible? (I have read that, you need to be in AWS vpc in order to connect. So do i have to move my local server to EC2 ?)
  • If yes, so what I am doing wrong in my above code.
Stennie
  • 63,885
  • 14
  • 149
  • 175
Alpit Anand
  • 1,213
  • 3
  • 21
  • 37

1 Answers1

3

If you do not belong to the same VPC with the DocumentDB, you cannot access as you specifically wrote. Check this article.

Basically, the article explains how to access the DocumentDB by ssh tunneling with an EC2 which is in the same VPC. Since the EC2 locates in the VPC, it is possible to connect the DocumentDB from EC2 and your local code can connect the DB through the EC2.

Lamanus
  • 12,898
  • 4
  • 21
  • 47
  • So, in a nut shell, i have to run ssh command in order to connect with remote documentDb ? – Alpit Anand Jul 30 '19 at 13:51
  • @AlpitAnand Yeap, you need a kind of NAT gateway to connect the private DocumentDB with your public PC. – Lamanus Jul 30 '19 at 13:53
  • 1
    In windows, [THIS](https://stackoverflow.com/questions/4974131/how-to-create-ssh-tunnel-using-putty-in-windows) will be helpful. – Lamanus Jul 30 '19 at 14:02