title: Nodejs - Invoke an AWS.Lambda function from within another lambda function
body: <p>I have the following function which I use to invoke a Lambda function from within my code.</p>
  
  <p>However when I try to use it within a Lambda function, I get the following error: </p>
  
  <pre><code>AWS lambda undefined 0.27s 3 retries] invoke({ FunctionName: 'my-function-name',
    InvocationType: 'RequestResponse',
    LogType: 'Tail',
    Payload: &lt;Buffer &gt; })
  </code></pre>
  
  <p>How can I invoke a Lambda function from within a Lambda function?</p>
  
  <p>My function:</p>
  
  <pre><code>'use strict';
  
  var AWS = require("aws-sdk");
  
  var lambda = new AWS.Lambda({
      apiVersion: '2015-03-31',
      endpoint: 'https://lambda.' + process.env.DYNAMODB_REGION + '.amazonaws.com',
      logger: console
  });
  
  var lambdaHandler = {};
  
  // @var payload - type:string
  // @var functionName - type:string
  lambdaHandler.invokeFunction = function (payload, functionName, callback) {
  
      var params = {
          FunctionName: functionName, /* required */
          InvocationType: "RequestResponse",
          LogType: "Tail",
          Payload: new Buffer(payload, 'utf8')
      };
  
      var lambdaRequestObj = lambda.invoke(params);
  
      lambdaRequestObj.on('success', function(response) {
          console.log(response.data);
      });
  
      lambdaRequestObj.on('error', function(response) {
          console.log(response.error.message);
      });
  
      lambdaRequestObj.on('complete', function(response) {
          console.log('Complete');
      });
  
      lambdaRequestObj.send();
  
      callback();
  };
  
  module.exports = lambdaHandler;
  </code></pre>