Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error while executing lambda through step functions

I am executing step function. but, i am getting error in execution of one state.

It giving error : Lambda.Unknown cause: The cause could not be determined because Lambda did not return an error type.

My lambda function calls external webservice. I don't want to wait until webservice response is received.

Can we return data from function without waiting for webservice response ??

My Lambda function

var http = require('http');
exports.handler = (event, context, callback) => {

    var inputJson= {};

    inputJson.firstname= event.firstname; 
    inputJson.lastname= event.lastname;
    inputJson.workspacename= event.workspacename;
    inputJson.customermailid= event.customermailid;
    inputJson.mobilenumber= event.mobilenumber;
    inputJson.orgname= event.orgname;

    inputJson.sessionid= event.sessionid;

    var post_data = JSON.stringify({
        "domainname" : inputJson.domainname,
        "orgname" : inputJson.orgname,
        "customermailid" : inputJson.customermailid,
        "adminmailid":"[email protected]",
        "product":3
    });

  // An object of options to indicate where to post to
  var post_options = {
      host: 'host_ip',
      path: 'path',
      method: 'POST',
      headers: {
          'Content-Type': 'application/json'
      }
  };

  // Set up the request
  var post_req = http.request(post_options, function(res) {
      res.setEncoding('utf8');

  });

   post_req.on('error', function (event) {
          console.log('Response: Error=' + event);
          callback(null, inputJson);
   });

  // post the data
  post_req.write(post_data);
  post_req.end();

  callback(null, inputJson);

};
like image 514
Kaustubh Khare Avatar asked Jun 22 '17 12:06

Kaustubh Khare


1 Answers

The following one only answers to this question mentioned above: error : Lambda.Unknown cause: The cause could not be determined because Lambda did not return an error type.




Standard Workflows guarantee exactly one execution of each workflow step, with a maximum duration of one year.

This is from the Step function documentation. It means your step which is invoking your Lambda function has a timeout of almost 1 year. Whereas if you see the Lambda function there's a timeout option.

Now, if your lambda function has a timeout, say for X seconds and the task of the Lambda function takes more than X seconds then your lambda will timeout and won't return any response back to the Step function. This can also generate the above error you mentioned!

But I believe you already know these since it's already been 2 years and 6 months and .... :v :v

like image 107
sphoenix Avatar answered Oct 28 '22 14:10

sphoenix