{"id":13505641,"url":"https://github.com/vvo/aws-lambda-nodejs-webpack","last_synced_at":"2025-03-30T00:31:20.115Z","repository":{"id":46889467,"uuid":"281355908","full_name":"vvo/aws-lambda-nodejs-webpack","owner":"vvo","description":"λ CDK Construct to build Node.js AWS lambdas using webpack","archived":true,"fork":false,"pushed_at":"2021-10-05T14:10:04.000Z","size":4540,"stargazers_count":31,"open_issues_count":11,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-16T06:31:06.193Z","etag":null,"topics":["aws","aws-cdk","aws-lambda","cdk-construct","webpack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vvo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"vvo"}},"created_at":"2020-07-21T09:36:55.000Z","updated_at":"2023-03-11T12:21:32.000Z","dependencies_parsed_at":"2022-09-05T10:50:59.004Z","dependency_job_id":null,"html_url":"https://github.com/vvo/aws-lambda-nodejs-webpack","commit_stats":null,"previous_names":["vvo/aws-lambda-nodejs-rollup"],"tags_count":18,"template":false,"template_full_name":"vvo/javascript-library-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvo%2Faws-lambda-nodejs-webpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvo%2Faws-lambda-nodejs-webpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvo%2Faws-lambda-nodejs-webpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvo%2Faws-lambda-nodejs-webpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vvo","download_url":"https://codeload.github.com/vvo/aws-lambda-nodejs-webpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246117691,"owners_count":20726068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cdk","aws-lambda","cdk-construct","webpack"],"created_at":"2024-08-01T00:01:10.984Z","updated_at":"2025-03-30T00:31:15.107Z","avatar_url":"https://github.com/vvo.png","language":"TypeScript","readme":"**Update from the maintainer**: Unless you have a good reason to use Webpack with AWS lambda, you should use the default CDK construct (https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html). It works really well and is even faster than this Webpack based project, thanks to esbuild. I initially wrote this Webpack based construct because, at the time, the official Node.js construct was very slow. Since September 2021 I now use the default Node.js construct.\n\nConsider this package deprecated as I won't be maintaining it, but it works.\n\n# aws-lambda-nodejs-webpack ![npm](https://img.shields.io/npm/v/aws-lambda-nodejs-webpack) [![Mentioned in Awesome CDK](https://awesome.re/mentioned-badge.svg)](https://github.com/eladb/awesome-cdk) [![GitHub license](https://img.shields.io/github/license/vvo/aws-lambda-nodejs-webpack?style=flat)](https://github.com/vvo/aws-lambda-nodejs-webpack/blob/master/LICENSE) [![Tests](https://github.com/vvo/aws-lambda-nodejs-webpack/workflows/CI/badge.svg)](https://github.com/vvo/aws-lambda-nodejs-webpack/actions) ![npm](https://img.shields.io/npm/dy/aws-lambda-nodejs-webpack)\n\n---\n\n_[CDK](https://aws.amazon.com/cdk/) Construct to build Node.js AWS lambdas using [webpack](https://webpack.js.org/)_\n\n_Table of contents:_\n\n- [Usage example](#usage-example)\n- [Features](#features)\n- [Why?](#why)\n- [Roadmap](#roadmap)\n- [How to make changes and test locally](#how-to-make-changes-and-test-locally)\n- [WTF happened to the rollup version?](#wtf-happened-to-the-rollup-version)\n- [Thanks](#thanks)\n\n## Usage example\n\n```bash\nyarn add aws-lambda-nodejs-webpack\n```\n\n```js\n// infra/super-app-stack.js\nconst sns = require(\"@aws-cdk/aws-sns\");\nconst subscriptions = require(\"@aws-cdk/aws-sns-subscriptions\");\nconst core = require(\"@aws-cdk/core\");\nconst { NodejsFunction } = require(\"aws-lambda-nodejs-webpack\");\n\nmodule.exports = class SuperAppProductionStack extends core.Stack {\n  constructor(scope, id, props) {\n    super(scope, id, props);\n\n    const slackNotificationsLambda = new NodejsFunction(\n      this,\n      \"slack-notifications-lambda\",\n      {\n        entry: \"events/slack-notifications.js\", // required\n      },\n    );\n  }\n};\n```\n\n```js\n// events/slack-notifications.js\nimport { WebClient as SlackWebClient } from \"@slack/web-api\";\n\nexport function handler(event) {\n  const message = event.Records[0].Sns.Message;\n  // do something with message\n}\n```\n\n## Features\n\n- webpack 5\n- compiles and deploys to Node.js 14.x by default\n- fast, [no-docker](https://github.com/aws/aws-cdk/issues/9120) CDK construct\n- lambda output only contains the necessary files, no README, tests, ...\n- bundling happens in temporary directories, it never writes in your project directory\n- source map support\n- TypeScript support\n- Babel support (preset-env)\n- babel \u0026 webpack caching\n- node_modules are split into a single `vendor.js` file. Allowing you to debug your own code in AWS console most of the time\n\n## Why?\n\nThere's already a dedicated [aws-lambda-nodejs module for CDK](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html) but I had two major issues with it:\n\n1. **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](https://docs.docker.com/docker-for-mac/mutagen/)), while significantly faster, still takes 20s just to mount a Node.js project.\n2. aws-lambda-nodejs generates a single file bundle 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.\n\nI want to be clear: I respect a LOT the work of the CDK team, and especially [@jogold](https://github.com/jogold/), author of aws-lambda-nodejs) that helped me a lot into debugging performance issues and explaining to me how everything works.\n\n## Caveats\n\n⚠️ the only configuration file from your project that we will read is `tsconfig.json` (not including compilerOptions, which are overwritten using https://www.npmjs.com/package/@tsconfig/node12).\n\nOther files won't be used (example: .babelrc). If you need to reuse part of your babel configuration, please open an issue with details on your usecase so we can build the best API for how to do this.\n\n## How to make changes and test locally\n\n```\n// fork and clone\ncd aws-lambda-nodejs-webpack\nyarn\nyarn link\nyarn start\n\n# in another terminal and project where you want to test changes\nyarn link aws-lambda-nodejs-webpack\n# cdk commands will now use your local aws-lambda-nodejs-webpack\n```\n\n## Thanks\n\n- the CDK team for this awesome project\n- [@jogold](https://github.com/jogold/) for his time while helping me debugging performance issues on Docker\n","funding_links":["https://github.com/sponsors/vvo"],"categories":["Language Support"],"sub_categories":["Multi-accounts setup"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvo%2Faws-lambda-nodejs-webpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvvo%2Faws-lambda-nodejs-webpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvo%2Faws-lambda-nodejs-webpack/lists"}