Skip to content

Latest commit

 

History

History
89 lines (66 loc) · 1.52 KB

README.md

File metadata and controls

89 lines (66 loc) · 1.52 KB

Lambdur

Simple Lambda & Cloud Function wrapper written in Typescript.

Get Started

Install with yarn.

yarn add lambdur

Usage

Import and chain your handlers.

import { Lambdur } from "lambdur";
import { ExampleMiddleware } from "./middleware";

const ExampleHttpHandler = () => ({
  statusCode: 200,
  body: "foo"
});

export const handler = Lambdur.chain(
  Lambdur.Handler.Type.HTTP,
  ExampleMiddleware,
  ExampleHttpHandler,
);

Types

Lambdur provides types for specific types for AWS CRON, HTTP, SNS and SQS request and response properties.

import { Lambdur } from "lambdur";

const ExampleHttpHandler: Lambdur.Handler<ExampleHttpHandler.Request, ExampleHttpHandler.Response> = async (request, context, callback) => {

  await new Promise(r => setTimeout(() => r(), 1000));

  return {
    statusCode: 200,
    body: {
      greeting: `Hello ${request.body.name}`,
      ts: new Date().getTime(),
    },
  }
}

export const handler = Lambdur.chain(ExampleHttpHandler);

export namespace ExampleHttpHandler {
  export interface Request extends Lambdur.Handler.Request.HTTP {
    body: {
      name: string;
    }
  }
  export interface Response extends Lambdur.Handler.Response {
    body: {
      greeting: string;
      ts: number;
    }
  }
}

Development

This is a pure Typescript package, no bundling necessary.

NPM Scripts

Buid script
yarn run build
Watch script
yarn run watch
Lint script
yarn run lint