lambda-init
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

lambda-init

Initialize your lambda function (or similar serverless apps) before processing user requests without headache.

Purpose

Have you ever wanted to initialize your app in a serverless environment like AWS lambda that needs some sort of initialization like connecting to the database or similar tasks which needs async code execution?

You may be familiar with the pattern below.

// my-awesome-lambda-function.ts

const initialize = (async () => {})();

const handler = async (event, context) => {
  // only resolves the promise once
  const app = await initialize;

  // the rest of your handler
};

But wait! What if:

  • How do you want to tell the user to wait if app initialization takes 5 seconds? (or more)
  • App initialization fails?

Usage

lambda-init supports both sync and async app initialization. However, the main use case is when your needs async initialization.

// my-awesome-lambda-function.ts
import { AppLoader, withAppLoader } from 'lambda-init';


const appLoader = new AppLoader(
  async () => {
    // initialize your app here
  }
);

const handler = withAppLoader(
  appLoader,

  // Lambda handler
  async (event, context) => {
  
  const app = appLoader.app;

  // the rest of your handler
});

Development

TBD.

References

Compile Typescript Packages to Multiple format

Package Sidebar

Install

npm i lambda-init

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

7.51 kB

Total Files

9

Last publish

Collaborators

  • dmanavi