All Projects → vvo → aws-lambda-nodejs-webpack

vvo / aws-lambda-nodejs-webpack

Licence: MIT License
λ CDK Construct to build Node.js AWS lambdas using webpack

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to aws-lambda-nodejs-webpack

projen-test
An example project explaining how to create and publish CDK constructs using projen and jsii. It lets you publish your CDK constructs to npm, Maven, NuGet and PyPi.
Stars: ✭ 23 (-28.12%)
Mutual labels:  aws-lambda, aws-cdk
cdk-esbuild
CDK constructs for esbuild, an extremely fast JavaScript bundler
Stars: ✭ 44 (+37.5%)
Mutual labels:  aws-cdk, cdk-construct
amazon-eventbridge-cdk-audit-service-sample
Sample of a decoupled audit service using Amazon EventBridge and AWS Step Functions. Provisioned with AWS CDK.
Stars: ✭ 25 (-21.87%)
Mutual labels:  aws-lambda, aws-cdk
next-serverless
☁️ next-serverless deploys your next.js application to AWS Lambda with minimal or even no configuration.
Stars: ✭ 80 (+150%)
Mutual labels:  aws-lambda
SSR-React-Using-Serverless
SSR-React Using Serverless(aws)
Stars: ✭ 34 (+6.25%)
Mutual labels:  aws-lambda
lambda-facebook-oauth
An AWS Lambda function to facilitate Oauth2 social login with Facebook
Stars: ✭ 16 (-50%)
Mutual labels:  aws-lambda
symfony-messenger
Bridge to use Symfony Messenger on AWS Lambda with Bref
Stars: ✭ 48 (+50%)
Mutual labels:  aws-lambda
mysql2-lambda
Precompiled Mysql2 Gem for AWS Lambda
Stars: ✭ 19 (-40.62%)
Mutual labels:  aws-lambda
webpack-aws-lambda
AWS Lambda that runs webpack and output the bundle.js file
Stars: ✭ 12 (-62.5%)
Mutual labels:  aws-lambda
lifebot
Use Google Sheets to log your life by texting it Emojis and pulling in data from Fitbit automatically.
Stars: ✭ 15 (-53.12%)
Mutual labels:  aws-lambda
aws-lambda-ebs-backups
Python scripts to be run using AWS's Lambda service to Backup and Delete Snapshots of EBS Volumes
Stars: ✭ 31 (-3.12%)
Mutual labels:  aws-lambda
c3
𝗖𝟯 provides compliant AWS CDK components to various security standards.
Stars: ✭ 24 (-25%)
Mutual labels:  aws-cdk
MCU-Countdown
An API for answering the question "When is the next MCU film?"
Stars: ✭ 95 (+196.88%)
Mutual labels:  aws-lambda
aws-lambda-static-ip
AWS Lambda static outgoing IP address
Stars: ✭ 46 (+43.75%)
Mutual labels:  aws-lambda
aws-lambda-pdf-generator-puppeteer
PDF generator for AWS lambda with puppeteer
Stars: ✭ 52 (+62.5%)
Mutual labels:  aws-lambda
terraform-aws-ec2-ami-backup
Terraform module for automatic & scheduled AMI creation
Stars: ✭ 19 (-40.62%)
Mutual labels:  aws-lambda
aws-iam-slack-notifer
Notifies slack when an IAM policy is created, changed or assigned to a role
Stars: ✭ 35 (+9.38%)
Mutual labels:  aws-lambda
aws-lambda-youtube-dl
Download YouTube (and a few other sites) videos to S3 using Lambda.
Stars: ✭ 78 (+143.75%)
Mutual labels:  aws-lambda
serverless-data-pipeline-sam
Serverless Data Pipeline powered by Kinesis Firehose, API Gateway, Lambda, S3, and Athena
Stars: ✭ 78 (+143.75%)
Mutual labels:  aws-lambda
aws-appsync-alternative-data-sources
Exploring how AWS AppSync can utilize AWS Lambda to integrate with alternative data sources, including Amazon ElastiCache and Amazon Neptune.
Stars: ✭ 13 (-59.37%)
Mutual labels:  aws-lambda

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.

Consider this package deprecated as I won't be maintaining it, but it works.

aws-lambda-nodejs-webpack npm Mentioned in Awesome CDK GitHub license Tests npm


CDK Construct to build Node.js AWS lambdas using webpack

Table of contents:

Usage example

yarn add aws-lambda-nodejs-webpack
// 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-webpack");

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

  • webpack 5
  • compiles and deploys to Node.js 14.x by default
  • fast, no-docker CDK construct
  • 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
  • TypeScript support
  • Babel support (preset-env)
  • babel & webpack caching
  • node_modules are split into a single vendor.js file. Allowing you to debug your own code in AWS console most of the time

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 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.

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.

Caveats

⚠️ 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).

Other 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.

How to make changes and test locally

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

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

Thanks

  • the CDK team for this awesome project
  • @jogold for his time while helping me debugging performance issues on Docker
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].