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);
};