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)

preguntada hace un año873 visualizaciones
1 Respuesta
0

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

profile picture
EXPERTO
respondido hace un año
  • 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

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas