export function run()

in src/index.ts [24:65]


export function run(
  appRootOrHandler: string | HandlerFunction,
  handler: string = ""
): void {
  if (!process.env.AWS_LAMBDA_RUNTIME_API) {
    throw new Error("Missing Runtime API Server configuration.");
  }
  const client = new RuntimeClient(process.env.AWS_LAMBDA_RUNTIME_API);

  const errorCallbacks = {
    uncaughtException: (error: Error) => {
      client.postInitError(error, () => process.exit(129));
    },
    unhandledRejection: (error: Error) => {
      client.postInitError(error, () => process.exit(128));
    },
  };

  process.on("uncaughtException", (error) => {
    console.error("Uncaught Exception", Errors.toFormatted(error));
    errorCallbacks.uncaughtException(error);
  });

  process.on("unhandledRejection", (reason, promise) => {
    const error = new Errors.UnhandledPromiseRejection(
      reason?.toString(),
      promise
    );
    console.error("Unhandled Promise Rejection", Errors.toFormatted(error));
    errorCallbacks.unhandledRejection(error);
  });

  BeforeExitListener.reset();
  process.on("beforeExit", BeforeExitListener.invoke);

  const handlerFunc = isHandlerFunction(appRootOrHandler)
    ? appRootOrHandler
    : (UserFunction.load(appRootOrHandler, handler) as HandlerFunction);
  const runtime = new Runtime(client, handlerFunc, errorCallbacks);

  runtime.scheduleIteration();
}