WHOATEMYNOODLES
WHOATEMYNOODLES

Reputation: 2643

Http Request not being ran unsure what the issue is

Been debugging all night, but I can't figure out why my http request is not being called

return getWordDefinition(queryUrl).then(function(responseMsg) {
    //Perform some other business logic
},
  function(err) {
      console.log('Error Getting Definition: ' + err);
});     

The function I'm trying to call:

function getWordDefinition(queryUrl){
    
    const options = {
    method: "GET"
  };

    return new Promise(function(resolve, reject) {
        const request = https.request(queryUrl, options, function(response) {

        console.log("STATUS CODE: " + response.statusCode);  // <------Not being called

        var data;
        response.on("data", function(chunk) {
          if (!data) {
            data = chunk;
          } else {
            data += chunk;
          }
        });
    
        response.on("end", function() {
          console.log("Data: " + JSON.stringify(data));
          resolve("Finished getting data");
        });
        
        request.on('error', (e) => {
          reject("ERROR ON REQUEST: " + e.message);
        });
        
        request.end();
        
      });
    });
  
}

This code is inside my AWS lambda function which seems to be timing out. I'm logging the status code for the http request, but it's never being called in my function. What am I doing incorrectly?

Upvotes: 0

Views: 47

Answers (1)

jarmod
jarmod

Reputation: 78840

Your Lambda is making an HTTP request and it appears to be timing out?

Here are 3 possible reasons, in descending order of likelihood:

  1. it's running in VPC and you've given the Lambda no route to the internet
  2. the HTTP request takes longer than the Lambda timeout (default is 3 seconds)
  3. your async/promise code has a bug

See Internet and service access for VPC-connected functions for #1.

Upvotes: 1

Related Questions