title: Share code between AWS lambda functions in node.js
body: <p>It seems it is not possible to pass around some code (containing data and functions) that is invoked as a AWS lambda function within another AWS lambda function.</p>
  
  <p>For example, take this <code>customConfigLambda</code>:</p>
  
  <pre><code>var callbackPayload = {};
  
  callbackPayload.fooData = 'fooFromData';
  callbackPayload.fooFunction = function() {return 'fooFromFunction'; };
  
  exports.handler = (event, context, callback) =&gt; {
      callback(null, callbackPayload);
  };
  </code></pre>
  
  <p>When I call the previous AWS lambda function in another AWS lambda function like here:</p>
  
  <pre><code>var AWS = require('aws-sdk');
  AWS.config.update({accessKey: '123', secretAccessKey: 'abc', region: 'us-east-1' });
  var lambda = new AWS.Lambda({region: 'us-east-1'});
  
  exports.handler = (event, context, callback) =&gt; {
      var params = {FunctionName: 'customConfigLambda'};
      lambda.invoke(params, function(err, callbackPayload) {
          if (err) {
              // do nothing
          }
          else {
              console.log('callbackPayload:', JSON.stringify(callbackPayload, null, 2));
          }
      });
  };
  </code></pre>
  
  <p>Then I can see only <code>callbackPayload.fooData</code> but not <code>callbackPayload.fooFunction</code>.</p>
  
  <p>How can I have some <code>callbackPayload.fooFunction(s)</code> shared between multiple other AWS lambda functions?</p>