0

I want to call a get service without receiving its response. Basically that service is a long running process that takes around a minute to respond. To save the Lambda cost I am looking to call it and terminate the function immediately. Following function is called successfully but server doesn't receive request, but if I comment out context.succeed() then server receives request and function is throwing "Process exited before completing request"

Here is the code:

var url = require('url');

var config = {
    "endpoint_url":"http://www.google.com",
    "api_user" : "",
    "api_secret": "",
    "function_name": "Stage_FunctionName"
};

exports.handler = function(event, context) {
  var https;
  var host, port, path, parsed_url; 
  parsed_url = url.parse(config.endpoint_url);

  host = parsed_url.hostname;
  port = parsed_url.port;
  path = parsed_url.pathname;

  if(parsed_url.protocol==='https:'){
    https = require('https')  
  }
  else{
    https = require('http')
  }       

  var headers = {'Content-Type': 'application/json'};
  var method = 'GET';
  var options = {
        host: host,
        port: port,
        path: path,
        method: method,
        headers: headers
    };    

  var req = https.request(options);
  req.end();
  console.log(config.function_name + ' - ' + 'Request Sent to ' + config.endpoint_url);
  context.succeed(config.function_name + ' - ' + 'Request Sent to ' + config.endpoint_url);
};
Sadiq Khoja
  • 522
  • 1
  • 5
  • 23
  • Can you show the log output? I believe the error can be because you are calling req.end() before context.succeed() (could be also context.done()). – filipebarretto Mar 29 '16 at 17:25
  • Execution result: succeeded ---- Cloud Watch Logs: START RequestId: c6a95eed-f63b-11e5-9a43-3bbbf8297b08 Version: $LATEST 2016-03-30T05:53:50.499Z c6a95eed-f63b-11e5-9a43-3bbbf8297b08 Stage_PatientCommunication - Request Sent to http://stage.neutrinomed.com/SendScheduledMessages END RequestId: c6a95eed-f63b-11e5-9a43-3bbbf8297b08 REPORT RequestId: c6a95eed-f63b-11e5-9a43-3bbbf8297b08 Duration: 277.43 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 9 MB – Sadiq Khoja Mar 30 '16 at 05:55

0 Answers0