{"size": 987, "ext": "js", "max_stars_repo_path": "packages/appsync-emulator-serverless/lambdaRunner.js", "max_stars_repo_name": "darlintonprauchner/aws-utils", "max_stars_repo_stars_event_min_datetime": "2018-08-31T20:35:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-27T14:41:13.000Z", "max_issues_repo_path": "packages/appsync-emulator-serverless/lambdaRunner.js", "max_issues_repo_name": "darlintonprauchner/aws-utils", "max_issues_repo_issues_event_min_datetime": "2018-05-19T16:07:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-18T19:01:08.000Z", "max_forks_repo_path": "packages/appsync-emulator-serverless/lambdaRunner.js", "max_forks_repo_name": "darlintonprauchner/aws-utils", "max_forks_repo_forks_event_min_datetime": "2018-06-05T20:02:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-19T11:52:44.000Z"}
{"max_stars_count": 52, "max_issues_count": 126, "max_forks_count": 48, "avg_line_length": 23.5, "max_line_length": 78, "alphanum_fraction": 0.5764944276}
const {
  log,
  sendErr,
  sendOutput,
  installExceptionHandlers,
} = require('./lambda/util');

process.once(
  'message',
  async ({ module, handlerPath, handlerMethod, payload }) => {
    try {
      log.info('load', module);
      // eslint-disable-next-line
      const handlerModule = require(module);
      if (!handlerModule[handlerMethod]) {
        throw new Error(
          `Module : ${handlerPath} does not have export: ${handlerMethod}`,
        );
      }

      log.info('invoke', handlerMethod);
      const lambda = handlerModule[handlerMethod];
      const context = {};
      const lambdaResult = lambda(payload, context, (err, callbackResult) => {
        if (err) {
          sendErr(err);
        } else {
          sendOutput(callbackResult);
        }
      });
      if (lambdaResult instanceof Promise) {
        sendOutput(await lambdaResult);
      }
    } catch (err) {
      log.error(err);
      sendErr(err);
    }
  },
);

installExceptionHandlers();
