apex-utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

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

/apex-utils/

    Package Sidebar

    Install

    npm i apex-utils

    Weekly Downloads

    1

    Version

    0.0.5

    License

    MIT

    Last publish

    Collaborators

    • staszek