lib/plugins/aws/invokeLocal/index.js/AwsInvokeLocal/invokeLocalNodeJs
class AwsInvokeLocal:  invokeLocalNodeJs(handlerPath, handlerName, event) {
    let lambda;

    try {
      /*
       * we need require() here to load the handler from the file system
       * which the user has to supply by passing the function name
       */

      const handlersContainer = require( // eslint-disable-line global-require
        path.join(
          this.serverless.config.servicePath,
          this.options.extraServicePath || '',
          handlerPath
        )
      );
      lambda = handlersContainer[handlerName];
    } catch (error) {
      this.serverless.cli.consoleLog(error);
      process.exit(0);
    }

    const callback = (err, result) => {
      if (err) {
        let errorResult;
        if (err instanceof Error) {
          errorResult = {
            errorMessage: err.message,
            errorType: err.constructor.name,
          };
        } else {
          errorResult = {
            errorMessage: err,
          };
        }

        this.serverless.cli.consoleLog(chalk.red(JSON.stringify(errorResult, null, 4)));
        process.exitCode = 1;
      } else if (result) {
        if (result.headers && result.headers['Content-Type'] === 'application/json') {
          if (result.body) {
            try {
              Object.assign(result, {
                body: JSON.parse(result.body),
              });
            } catch (e) {
              throw new Error('Content-Type of response is application/json but body is not json');
            }
          }
        }

        this.serverless.cli.consoleLog(JSON.stringify(result, null, 4));
      }
    };


    const startTime = new Date();
    const context = {
      awsRequestId: 'id',
      invokeid: 'id',
      logGroupName: this.provider.naming.getLogGroupName(this.options.functionObj.name),
      logStreamName: '2015/09/22/[HEAD]13370a84ca4ed8b77c427af260',
      functionVersion: 'HEAD',
      isDefaultFunctionVersion: true,

      functionName: this.options.functionObj.name,
      memoryLimitInMB: '1024',

      succeed(result) {
        return callback(null, result);
      },
      fail(error) {
        return callback(error);
      },
      done(error, result) {
        return callback(error, result);
      },
      getRemainingTimeInMillis() {
        return (new Date()).valueOf() - startTime.valueOf();
      },
    };

    return lambda(event, context, callback);
  }