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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lambdalith

v0.4.1

Published

A tiny event router for AWS Lambda functions. Route SQS, SNS, EventBridge, and DynamoDB Streams events with a fluent API.

Readme

Lambdalith

GitHub Workflow Status GitHub npm npm

A lightweight, type-safe event router for AWS Lambda functions. Route SQS, SNS, EventBridge, and DynamoDB Streams events with a fluent API.

Features

  • 🔍 Automatic event detection – Identifies incoming event types without configuration.
  • 📦 Per-record processing – Handles batch events record-by-record in parallel or sequentially with partial failure support.
  • 🎯 Route matching – Filter by queue name, topic, source/detail-type, or table name.
  • ⚠️ Built-in error handling – Handle errors and unmatched events with ease.
  • 🦺 Full TypeScript support – Strongly typed contexts with auto-completion.
  • 🔧 Middleware support – Run middleware before and after handling each record.
  • 🪶 Lightweight – Zero dependencies.

Installation

npm install lambdalith

Quick Start

import { EventRouter } from 'lambdalith';

const router = new EventRouter();

router.sqs('MyQueue', (c) => {
	console.log(c.sqs.body);
});

router.sns('MyTopic', (c) => {
	console.log(c.sns.body);
});

router.event({ source: 'MyService', detailType: 'MyEvent' }, (c) => {
	console.log(c.event.detail);
});

router.dynamodb('MyTable', (c) => {
	console.log(c.dynamodb.newImage);
});

router.onError((error, c) => {
	console.error(error.message);
});

router.notFound((c) => {
	console.warn('Unhandled', c.source);
});

export const handler = router.handler();

Route Matching

Routes are matched in registration order – the first matching route wins. Register specific routes before catch-alls:

router.sqs('SpecificQueue', (c) => {
	// will match the specific queue
});
router.sqs((c) => {
	// will match any other queue
});

Batch Processing

For SQS and DynamoDB Streams, the router automatically handles partial batch failures. Enable ReportBatchItemFailures on your function to take advantage of this feature.

Default (parallel): All records process concurrently. Failed records reported individually.

Sequential: Records process one at a time. Stops processing on failure and marks remaining records as failed.

router.sqs(
	'MyQueue.fifo',
	(c) => {
		// will process messages from my-queue sequentially
	},
	{ sequential: true },
);

Context

Each handler receives a context object with event-specific data and the Lambda context:

router.sqs((c) => {
	c.sqs; // SQS context
	c.lambda; // Lambda context
});

Error Handling

When an error handler is registered, errors are swallowed by default. To propagate an error (mark the record as failed or fail the invocation), rethrow it:

// Swallow error (log and continue)
router.onError((error, c) => {
	console.error(error.message);
});

// Propagate error (rethrow to fail)
router.onError((error, c) => {
	console.error(error.message);
	throw error; // Record marked as failed / invocation fails
});

If you do not register an error handler, errors always propagate to the router which will mark the record as failed.

// Called when no route matches
router.notFound((c) => {
	console.warn('Unhandled:', c.source);
	console.log(c.raw);
});

Middleware

Middleware runs for each record in onion-style order. The first registered middleware wraps the last:

middleware1
    middleware2
        handler
    middleware2
middleware1

Add a middleware to the router:

router.use(async (c, next) => {
	console.log('before');
	await next();
	console.log('after');
});

Middleware must call next() to continue. Returning without calling next() skips the rest of the middleware chain and the handler, treating the event as successfully handled.

Filter middleware by event type:

router.use('sqs', async (c, next) => {
	// Only runs for SQS events
	await next();
});

router.use('sns', snsMiddleware);
router.use('event', eventBridgeMiddleware);
router.use('dynamodb', dynamodbMiddleware);

Testing

Use router.test() to send test events to the router to ensure your handlers are called correctly.

describe('Example', () => {
  const testRouter = router.test();
  test('sqs routing', async () => {
    const res = await testRouter.send.sqs({
      queue: 'orders-queue',
      body: { orderId: '123' },
    });
    expect(res).toEqual({ batchItemFailures: [] });
  }
})

Contributing

Please see CONTRIBUTING.md for contribution guidelines.

License

MIT