Aws Lambda - Nodejs Function Will Not Return Data
I'm new to NodeJS function calls and I have been banging my head on the screen for a few hours now and all my googling just hasn't helped. So what I have is a AWS Lambda function
Solution 1:
Once you have invoked a function in JavaScript that has a callback as an argument, you can not get a value out of the callback by a return, because this function executes asynchronously. In order to get the value from the callback, this callback must invoke the lambda functions callback function eventually.
In your case the function "returningData" needs to call the lambda callback function.
This would be the structure:
exports.lambda = (event, lambdaContext, callback) => { // this is the lambda functionfunctionreturningData(data){
console.log("ReturningData Function Being Called!");
var body = '{"Error":null,"Message":null,"Success":true,"ExternalId":"201609260000003","SentTimeStamp":"11/22/2016 1:07:36 PM","RespTimeStamp":"11/22/2016 1:08:32 PM","RespTot":"SRE"}';
callback(null, JSON.parse(body)); // this "returns" a result from the lambda function
}
functiongetJson(myid, callback2){
request('http://server.com/service1.asmx/Get_Status_By_External_Id?externalId=' + myid + '', function (error, response, body) {
console.log(body); // I see the JSON results in the console!!!callback2(body);
});
}
query_result.success = 1;
query_result.message = "Applicant Data Found";
query_result.data = getJson(201609260000003, returningData);
};
Post a Comment for "Aws Lambda - Nodejs Function Will Not Return Data"