0.0.5 • Published 8 years ago

apex-utils v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Apex Utils

Collection of helpers useful in a work with Node.js on AWS Lambda inspired by node-apex.

Installation

$ npm install apex-utils --save

Features

  • Build on promises
  • Throws uncaught errors to lambda callback
  • API Gateway handler creator
  • TypeScript ready
  • No external dependencies

Examples

import { createLambda } from "apex-utils";

interface IEvent {
  name: string;
}

export const handler = createLambda(({event, context}) => {
  const { name } = event as IEvent;
  if (name === "world") {
    throw "error"; // call callback with throwed error and null data
  }
  return `Hello ${name}!`; // call callback with null error and returned value
});

export const asyncHandler = createLambda(async ({event, context}) => {
  const name = await new Promise((resolve, reject) => {
    const { name } = event as IEvent;
    if (name === "world") {
      reject("error"); // call callback with rejected error and null data
    } else {
      resolve(name);
    }
  });
  return `Hello ${name}!`; // call callback with null error and returned value
});

More Examples

License

The MIT License

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago