AWS Lambda连接DocumentDb实例得到MongoServerSelectionError: getaddr



在尝试将lambda连接到documentdb时得到以下错误日志。

TART RequestId: 0946e4e9-9364-4af2-9802-7ea2d8b946d5 Version: $LATEST
2021-08-18T16:25:11.958Z    0946e4e9-9364-4af2-9802-7ea2d8b946d5    INFO    insideHandler
2021-08-18T16:25:42.296Z    0946e4e9-9364-4af2-9802-7ea2d8b946d5    ERROR   MongoServerSelectionError: getaddrinfo EAI_AGAIN sample-dev-01-instance1.abcde.us-east-1.docdb.amazonaws.com
at Timeout._onTimeout (/var/task/node_modules/mongodb/lib/sdam/topology.js:325:38)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'sample-dev-01-instance1.abcde.us-east-1.docdb.amazonaws.com:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
}
}

lambda的VPC与documentdb实例相同。nodejs代码在本地运行时成功连接实例,但在lambda中有问题。

const { MongoClient } = require('mongodb');
exports.handler = async(event, context) => {
console.log("insideHandler");
const uri = 'mongodb://username:password@sample-dev-01-instance1.abcde.us-east-1.docdb.amazonaws.com:27017';
const client = new MongoClient(uri, {
useNewUrlParser: true,
ssl: true,
tlsCAFile: `rds-combined-ca-bundle.pem`, //Specify the DocDB; cert
retryWrites: false
});
try {
await client.connect();
console.log("connect successfully");
return {
statusCode: 200,
body: JSON.stringify({ message: 'connect successfully' })
}
}
catch (e) {
console.error(e);
}
};

enter code here

EAI_AGAIN是DNS查找超时错误,意味着它是网络连接错误或代理相关错误。您能确认Lambda函数是否使用与DocumentDB集群相同的安全组吗?

相关内容

  • 没有找到相关文章

最新更新