简体   繁体   English

AWS Lambda 连接 DocumentDb 实例得到 MongoServerSelectionError: getaddrinfo EAI_AGAIN

[英]AWS Lambda connecting DocumentDb instance got MongoServerSelectionError: getaddrinfo EAI_AGAIN

Got following error logs when trying to connecting lambda to documentdb.尝试将 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 } }

the VPC of lambda is the same as documentdb instance. lambda 的 VPC 与 documentdb 实例相同。 The nodejs code connects the instance successfully when running in local but has the issue in lambda. 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 is a DNS lookup timed out error, means it is a.network connectivity error or proxy related error. EAI_AGAIN 是一个 DNS 查找超时错误,意味着它是一个网络连接错误或代理相关错误。 Can you confirm whether the Lambda function is using the same security group as the DocumentDB cluster?能否确认Lambda function是否与DocumentDB集群使用同一个安全组?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM