AWS Lambda failed with https request "getaddrinfo ENOTFOUND"

0

I just open simple aws lambda that is able to make HTTP and HTTP requests. Didn't configured nothing, just checked some requests with some urls that works - what mean my lambda able to make network requests. ** didnt created any role , any vpc ...just created simple lambda

I copy a working script from my local development environment into lambda and the https request get

**edit : I noticed that using ip adress in hostname instead the domain name with the rejectunauthorized:false will let me make the response. ofc i want to avoid this solution but maybe it can assit you to assist me.

"Error: getaddrinfo ENOTFOUND myUrl.co.il",
"    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)"

And heres the simple request :

export const handler = (event, context, callback) => {
    const params = {
        host: "myUrl.co.il", // myurl is without https! just the DNS
        path: "/login",
        // rejectUnauthorized: false
    };
    const req = https.request(params, function(res) {
        let data = '';
        console.log('STATUS: ' + res.statusCode);
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
            data += chunk;
        });
        res.on('end', function() {
            console.log("DONE");
            console.log(JSON.parse(data));
        });
    });
    req.end();
};

I dont know how to start troubleshoot it .

已提问 1 年前6193 查看次数
2 回答
0

This has to do with the underlying OS configuration. The error message comes from the OS, and is only passed to Node.js. Perhaps the file descriptor limit is reached, by some other tenant?

J_N__
已回答 2 个月前
-1

This is more of a Node.js issue than an AWS-specific issue.

If you look at your error message, you'll see node:dns. This means it's probably a DNS issue. Node is having trouble resolving the domain name. I've seen these errors before, and they can frequently be resolved by adjusting how to call the function. I suggest trying to call in the string format where you have built the URL:

const req = https.request('https://myUrl.co.il/login', function(res) {
  // ...
});

If you need to provide additional options, you can insert the options object between the URL and function.

profile picture
已回答 1 年前
  • @Jason Butz Thanks! I tried that but it didnt solved the issue. Also , maybe node having trouble resolving domain name but it hard to me to understand why it can solve it in my local development but failed in aws lambda. Do you have more suggestions? (based on your answere i found temp solution with using ip instead domain name , but also i must add rejectunauthorized , somthing i tried to avoid)

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则