Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 通过lambda连接到AWS DocumentDB时出现连接错误_Node.js_Amazon Web Services_Aws Lambda_Aws Documentdb - Fatal编程技术网

Node.js 通过lambda连接到AWS DocumentDB时出现连接错误

Node.js 通过lambda连接到AWS DocumentDB时出现连接错误,node.js,amazon-web-services,aws-lambda,aws-documentdb,Node.js,Amazon Web Services,Aws Lambda,Aws Documentdb,通过lambda从node.js连接到AWS DocumentDB时出现以下错误 {errorMessage:enoint:没有这样的文件或目录,请打开 “rds组合ca bundle.pem”,错误类型:Error,stackTrace:[Object.fs.openSync fs.js:646:18,Object.fs.readFileSync fs.js:551:33,对象。 /var/task/base/mongoose.base.js:8:13,Module.\u compile mo

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

{errorMessage:enoint:没有这样的文件或目录,请打开 “rds组合ca bundle.pem”,错误类型:Error,stackTrace:[Object.fs.openSync fs.js:646:18,Object.fs.readFileSync fs.js:551:33,对象。 /var/task/base/mongoose.base.js:8:13,Module.\u 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.\u 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,模块。\u编译 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.\u 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'));
错误来自eOne:没有这样的文件或目录,请打开“rds-combined-ca-bundle.pem”

那个文件似乎不存在。你能查一下路吗?您是否将证书嵌入lambda?

它应该是:

var ca = fs.readFileSync(path.join(__dirname + '/rds-combined-ca-bundle.pem'));
或者您可以定义:

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

var options = {
            ............
            sslCA:caBundle,

我已经在同一文件夹中添加了rds-combined-ca-bundle.pem文件。转到Lambda控制台,在函数代码中,再次检查.pem的路径file@hoangdv,它是我正在阅读它的同一个文件夹。它与上面给出的postrds-combined-ca-bundle.pem相同,并且您正在运行的文件在同一个文件夹中,对吗?你能在当前文件夹中共享ls-ls吗?4-rw-rw-r-1*************1094 Feb 27 19:01 mongoose.base.js 64-rwxrwx 1*************65484 Feb 12 13:20 rds-combined-ca-bundle.pem mongoose.base.js->这是我需要rds-combined-ca-bundle.pem的文件