10

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

};

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

Comments

4

You can, but it might not give the results you expect. Especially with your post error handling. However, if you want Lambda to return without waiting for your post response. You can set: context.callbackWaitsForEmptyEventLoop = false

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.