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)

질문됨 일 년 전873회 조회
1개 답변
0

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

profile picture
전문가
답변함 일 년 전
  • 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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠