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 .

asked a year ago5982 views
2 Answers
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__
answered a month ago
-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
answered a year ago
  • @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)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions