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

aws-lambda-nodejs-rollup

v1.1.3

Published

CDK Construct to build Node.js AWS lambdas using rollup.js

Downloads

4

Readme

aws-lambda-nodejs-rollup GitHub license Tests codecov npm


CDK Construct to build Node.js AWS lambdas using rollup.js

Table of contents:

Usage example

yarn add aws-lambda-nodejs-rollup
// infra/super-app-stack.js
const sns = require("@aws-cdk/aws-sns");
const subscriptions = require("@aws-cdk/aws-sns-subscriptions");
const core = require("@aws-cdk/core");
const { NodejsFunction } = require("aws-lambda-nodejs-rollup");

module.exports = class SuperAppProductionStack extends core.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const slackNotificationsLambda = new NodejsFunction(
      this,
      "slack-notifications-lambda",
      {
        entry: "events/slack-notifications.js", // required
      },
    );
  }
};
// events/slack-notifications.js
import { WebClient as SlackWebClient } from "@slack/web-api";

export function handler(event) {
  const message = event.Records[0].Sns.Message;
  // do something with message
}

Features

  • fast, no-docker CDK construct
  • lambda output respects original files structure and node_modules (no inlining)
  • lambda output only contains the necessary files, no README, tests, ...
  • bundling happens in temporary directories, it never writes in your project directory
  • source map support

Why?

There's already a dedicated aws-lambda-nodejs module for CDK but I had two major issues with it:

  1. CDK uses docker for anything lambda build related. This means it mounts your whole Node.js project (not just the lambda code) inside Docker before running a bundler like Parcel. This is perfectly fine and performant on Linux and Windows, but this is extremely slow on macOS: a single cdk synth would take 2 minutes for a 3 lines lambda. Since it might take a very long time for Docker on macOS to get as fast as on Linux. Even their latest update (mutagen), while significantly faster, still takes 20s just to mount a Node.js project.
  2. aws-lambda-nodejs generates single files bundles with every local and external module inlined. Which makes it very hard to debug and read on the AWS console. I wanted a lambda output that mimicks my project file organization.

I want to be clear: I respect a LOT the work of the CDK team, and especially @jogold, author of aws-lambda-nodejs) that helped me a lot into debugging performance issues and explaining to me how everything works.

Roadmap

This is a list of features I thought could be interesting to users. If you need on of them, please contribute to the project.

  • [ ] Allow passing rollup options, like externals
  • [ ] Allow usage without the need of entry: new NodejsFunction(this, "slack-notifications-lambda"); that would mimic https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html#nodejs-function
  • [ ] Generate a bundle where entry is moved to /index.js
  • [ ] Use jsii to build for other languages
  • [ ] Ask CDK team if this could live under their repositories
  • [ ] Allow native modules, with option nativeModules. They would have to be installed into a temp folder with npm_config_arch and npm_config_platform and aliased in rollup configuration
  • [ ] Add tests
  • [ ] Monorepo support
  • [ ] Other ideas?

How to make changes and test locally

// fork and clone
cd aws-lambda-nodejs-rollup
yarn
yarn link
yarn start

# in another terminal and project where you want to test changes
yarn link aws-lambda-nodejs-rollup
# cdk commands will now use your local aws-lambda-nodejs-rollup

Thanks

  • the CDK team for this awesome project
  • @jogold for his time while helping me debugging performance issues on Docker