-1

通过 lambda 从 node.js 连接到 AWS DocumentDB 时出现以下错误

{"errorMessage":"ENOENT: 没有这样的文件或目录,打开 '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)","模块._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)","re​​quire (internal/module. js:11:18)","对象。(/var/task/library/mongoLib/room.lib.js:1:84)","Module._compile (module.js:652:30)","对象.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)" ]}

这是我在 lambda 中的节点 js 文件

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'));
4

2 回答 2

1

它应该是:

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

或者您可以定义:

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

var options = {
            ............
            sslCA:caBundle,
于 2020-02-27T07:52:34.730 回答
0

错误来自ENOENT: no such file or directory, open 'rds-combined-ca-bundle.pem

那里似乎不存在该文件。你能检查路径吗?您是否使用 lambda 嵌入了证书?

于 2020-02-27T07:10:18.437 回答