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回答
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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ