npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

co-lambda-runner

v1.1.1

Published

an interface to run es6 generators as lambda functions

Downloads

4

Readme

co-lambda-runner

Run ES6 generators as Lambda functions + some help for working with API Gateway

Getting started

npm install --save co-lambda-runner

Usage

'use strict';

const LambdaRunner = require('co-lambda-runner')
  , DB = require('./db');

function *main(e) {
  let id = e.params.id;
  return yield DB.get(id);
}

module.exports = LambdaRunner(main);

API

LambdaRunner(generatorFunc, configObject) returns: a function with the signature lambda expects function(event, context, cb) {}

  • generatorFunc - an ES6 generator function, should return its final value or throw an error. Optionally, co-lambda-runner accepts a second
  • config - Optionally, LambdaRunner accepts a second argument, a configuration object:
    • addErrorPrefix (string, default: 'Error: ') - always add this string as a prefix to errors thrown. This is useful for working with API Gateway which can only decide on which HTTP Status code to return by running the functions output through a Regular Expression.
    • notFoundRegexp (regex, default: /Not found:/): A regular expression to run on the functions error message to determine that the cause of the error was a not-found resource. In this case LambdaRunner will not prepend the addErrorPrefix message. This is needed to work with API Gateway as well, in order to allow you to set a RegEx for setting 404 errors.
    • notFoundMessage (string, default: 'Not found: could not find resource'): a default message to display if the notFoundRegexp matched and no err.message is present
    • defaultMessage (string, default: Internal Error): a default message to show if no err.message is present on the thrown error.
    • onInit - function which returns a yieldable (promise, generator, etc.) to be called on lambda init
    • onSuccess - function which returns a yieldable (promise, generator, etc.) to be called on success
    • onError - function which returns a yieldable (promise, generator, etc.) to be called on fail

Example

// ... function defined

module.exports = LambdaRunner(generatorFunc, {
  addErrorPrefix: 'Oh no! ',
  notFoundRegexp: /Lost!/,
  notFoundMessage: 'Lost! could not find resource',
  defaultMessage: 'EEEEEK!',
  onError: (payload) => {
    console.error(payload.response.error)
    return Promise.resolve()
  },
  onSuccess: (payload) => {
    console.log(payload.response)
    return Promise.resolve()
  },
  onInit: (payload) => {
    console.log(payload.request) // get event
    console.log(payload.context) // request context
    return Promise.resolve()
  }
})

LambdaRunner.setDefaults(configObject)

Sets default values for config which will be applied to subsequent instances created by LambdaRunner()

LambdaRunner.getDefaults()

Returns the current defaults

LambdaRunner.resetDefaults()

Resets the defaults to their default values