Node unable to resolve dns on aws lambda function "getaddrinfo "

0

I have a simple HTTPS request that works well on my local envoiremnt. But on aws lambda it works for some urls only and for other urls it can't be resolved and I'm getting this error:

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

The script is just a simple https request:

 const params = {
        host: event.url , //  event.url is without https! just the DNS
        path: "/login",
    };
    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();
};

** When event.url = url1 it work on lambda and my local but when event.url = url2 it work only on my local, on lambda I got the getaddrinfo error. ** If i replace the event.url with the url ip address and add rejectUnauthorized:false" it will work on both urls on both envoiremnt. (ofc i dont like this solution , it just to demonstrate that the issue is with the dns resolver on aws lambda envoiremnt)

已提問 1 年前檢視次數 873 次
1 個回答
0

I don’t suppose url2 on your local machine is in your host file?

profile picture
專家
已回答 1 年前
  • I'm not sure what do u mean? both , url1 and url2 are just example to demonstrate that some url can't be resolved.

  • Yeah I was checking what ever url your not having an issue with wasn’t in your host file

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南