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

wooljs

v1.5.0

Published

A utility for building AWS Lambda functions

Downloads

11

Readme

Wool js

A wrapper for AWS Lambda functions adding an async handler for better function structure, a customizable logger, and better exception handling. More to come soon!

Works great with shep!

Why do you need this?

AWS Lambda is growing in popularity as a way to build functions for anything from serving web applications to moving massive amounts of logs between amazon services. Wool lets you build those functions without having to add logic for the features Wool covers every time you build an API or a custom lambda function.

Note: Wool does not run or build your functions or enable local testing. See shep for details on building and running functions!

Getting Started

Prerequisites

It will be helpful to have some existing experience with API gateway and Lambda. If you have never used either of these tools before, it is recommended to setup a function manually to see how things are done. Please refer to Amazon's own getting started guide

Installation

npm install wooljs

Wooljs uses async/await functions. You will need to install a babel-preset that enables these functions, like babel-preset-stage-3 or a plugin for async/await

Features

Logger

your-lambda-function.js

import { log } from 'wooljs'

log.info('wool is cool!')

will log:

{"time":"2014-05-18T23:47:06.545Z","functionName":"your-lambda-function","functionVersion":27374,"level":"info","name":"mymodule","message":"Starting mymodule#handler()"}

Wool's logger uses the log level declared in process.env.LOG_LEVEL (defaults to info), one of 4 levels with corresponding methods: log.debug(), log.info(), log.warn(), log.error()

For more details see the shep-logger repo

Async handler

your-lambda-function.js

import { asyncHandler } from 'wooljs'

export const handler = asyncHandler(

  // context and callback optional, asyncHandler takes care of the callback
  async (event, /* context, callback */) => {

    const foo = 'bar'

    return foo
  }
)

The benefit of the asyncHandler is to remove the overhead of managing callbacks, promise chains, and the context object in a typical AWS Lambda handler function. Simply write the code you need the function to execute, declare its return value and move on with your life.

The asyncHandler function wrapper will also log every event sent through your handler.

Exception handling and notifications

Currently, Wool will throw an error and write the error message to stdout with log.error(), and return callback(error) from the asyncHandler.

Airbrake

To add error notifications via airbrake, simply add AIRBRAKE_PROJECT_KEY and AIRBRAKE_PROJECT_ID to process.env and configure your Airbrake settings for that project. Wool will take care of the rest.

The Airbrake node package needs __dirname: true if you are using webpack.

Timeouts

AWS Lambda does not have the best logging when it comes to timeouts. Your functions will fail after your configured timeout setting, but lambda does not log any recent stack trace or helpful error.

Coming soon! Wool wraps Lambda's default timeout handling and throws an exception with a helpful stack trace and Wool's normal exception logging/notification.

Why the name 'wool'?

Wool is named as a wrapper for lambda functions, keeping with the theme established by shep

Development

Pull requests welcome!

Compile: npm run compile

Publish: npm run pub "publish" is reserved by npm

Linter: We use standard to lint our projects. Travis will run npm run lint for PRs and pushes in lieu of tests for now