Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1521

AWS Lambda: Error: getaddrinfo ENOTFOUND from API

$
0
0

I have created the following code which grabs a seralizedXmlFile object from an S3 bucket and pushes it to an API service. This returns FAIL with the logs showing

Error: getaddrinfo ENOTFOUND http://urlat errnoException (dns.js:28:10)at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

CODE:

const AWS = require('aws-sdk');const https = require('http');var s3 = new AWS.S3();var un;var pw;var seralizedXmlFile;let index = function index(event, context, callback) { //for testing I have named the bucket and key   var params = {  Bucket: "bucket", //event.bucketName,   Key:  "personnelData_50112404_635705766849654385.xml" //event.fileName};s3.getObject(params, function(data, err)  {   if (data)    {       let seralizedXmlFile = err.Body.toString('utf-8'); // Use the encoding necessary       console.log("objectData " + seralizedXmlFile);   }    });var ssm = new AWS.SSM({region: 'ap-southeast-2'});var paramsx = {'Names' : ['/App/ServiceUsername', '/App/ServicePassword'],'WithDecryption' : true};ssm.getParameters(paramsx, function(err, data) {  if (err) console.log(err, err.stack); // an error occurred  else     {console.log('data: '+ JSON.stringify(data));           // successful response  console.log('password: '+ data.Parameters[0].Value);   console.log('username: '+ data.Parameters[1].Value);   pw = data.Parameters[0].Value;  un = data.Parameters[1].Value;  }   const req = https.request('http:/url/api/SyncPersonnelViaAwsApi/Get/5', (res) => {                res.headers +'Authorization: Basic '+ un +':'+ pw;                let body = seralizedXmlFile;        console.log('Status:', res.statusCode);        console.log('Headers:', JSON.stringify(res.headers));        res.setEncoding('utf8');        res.on('data', (chunk) => body += chunk);        res.on('end', () => {            console.log('Successfully processed HTTPS response');           console.log('returned res: '+ res);                      callback(null, res);                          });    });    req.end();});};exports.handler = index;

I followed a Q and A I found on "Error: getaddrinfo ENOTFOUND" error when making an HTTPs request

and changed the code to

  var params = {    host: "http://URL",    path: "/api/SyncPersonnelViaAwsApi/Get/5"};var 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));

but again firing the same error....does anyone have any idea what the issue is?

I have also tested the web service api through POSTMAN, so I can confirm it is working

Thank You


Viewing all articles
Browse latest Browse all 1521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>