-1

getting the following error while connecting to AWS DocumentDB from node.js through lambda

{"errorMessage":"ENOENT: no such file or directory, open 'rds-combined-ca-bundle.pem'","errorType":"Error","stackTrace":["Object.fs.openSync (fs.js:646:18)","Object.fs.readFileSync (fs.js:551:33)","Object. (/var/task/base/mongoose.base.js:8:13)","Module._compile (module.js:652:30)","Object.Module._extensions..js (module.js:663:10)","Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)","Module.require (module.js:596:17)","require (internal/module.js:11:18)","Object. (/var/task/library/mongoLib/room.lib.js:1:84)","Module._compile (module.js:652:30)","Object.Module._extensions..js (module.js:663:10)","Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)"]}

here is my node js file in lambda

var ca = fs.readFileSync(path.join('./','rds-combined-ca-bundle.pem'));

var options = {
        keepAlive: true,
        poolSize: 30,
        socketTimeoutMS: 30000,
        autoReconnect: true,
        reconnectTries: Number.MAX_VALUE,
        reconnectInterval: 500,
        useCreateIndex: true,
        auth: {authdb: 'admin'},
        useFindAndModify: false,
        sslValidate: true,
        sslCA:ca,
        useNewUrlParser: true
}

var uri = 'mongodb://'+globalData.getConfigurationSettings("documentdb_username")+':'+globalData.getConfigurationSettings("documentdb_password")+'@'+globalData.getConfigurationSettings("documentdb_server")+':'+globalData.getConfigurationSettings("documentdb_port")+'/'+globalData.getConfigurationSettings("documentdb_db_name")+'?ssl=true&replicaSet=rs0&readPreference=secondaryPreferred';

mongoose.connect(uri, options)
.then(() => console.log('Connection to DB successful'))
.catch((err) => console.error(err,'Error'));
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
paradox
  • 153
  • 12

2 Answers2

1

It should be:

var ca = fs.readFileSync(path.join(__dirname + '/rds-combined-ca-bundle.pem'));

Or you can define :

import caBundle from "./rds-combined-ca-bundle.pem";

var options = {
            ............
            sslCA:caBundle,
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
  • it is same what is given above post – paradox Feb 28 '20 at 10:04
  • `rds-combined-ca-bundle.pem` and the file you are running are on the same folder, right ? can you share `ls -ls` in the current folder ? – Thanh Nguyen Van Feb 28 '20 at 10:08
  • 4 -rw-rw-r-- 1 ***** ***** 1094 Feb 27 19:01 mongoose.base.js 64 -rwxrwxrwx 1 ***** ***** 65484 Feb 12 13:20 rds-combined-ca-bundle.pem ( mongoose.base.js -> this is the file where i'm requiring rds-combined-ca-bundle.pem ) – paradox Feb 28 '20 at 13:53
0

The error comes from ENOENT: no such file or directory, open 'rds-combined-ca-bundle.pem

it seems that file doesn't exist there. can you check the path? did you embed the cert with lambda?

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54