question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-lambda-nodejs] Bundling performance issues

See original GitHub issue

❓ General Issue

The Question

In my stack I’ve created several lamdas using the new NodejsFunction from @aws-cdk/aws-lambda-nodejs. Functionally everything works fine, code in bundled with Parcel and the stack deploys without issues. There are however two (Parcel related?) performance issues:

  1. Bundling seems quite slow, my lambda has a few dependencies and it takes about 20 seconds to bundle it.
  2. When performing multiple tests for the same stack, tests are slow as the lambda bundling isn’t cached.

I’m wondering if this is the expected performance or if I’m missing something? I did some tests with webpack to manually bundle the Lambdas, this is about 3 times faster than webpack. I’m also wondering about the caching feature in Parcel, shouldn’t the second performance issue be tackled it?

How to reproduce

I’ve created a simple sample app to show the issue: https://github.com/jaapvanblaaderen/cdk-lambda-bundling-performance

The app contains a single stack with one lambda that’s referenced in two tests. In the test output you can observe that bundling an empty lambda function takes about 8 seconds (initially slow) and for the second test it’s still around 6-7 seconds (no/bad caching?).

Bundling asset simple-stack/HandlerLambda/Code/Stage...

 RUNS  lib/simple-stack.test.ts
✨ Built in 8.01s
Bundling asset simple-stack/HandlerLambda/Code/Stage...

 RUNS  lib/simple-stack.test.ts
✨ Built in 6.66s
 PASS  lib/simple-stack.test.ts (21.056 s)
  Simple Stack
    ✓ Should have memory size set to 512MB (9505 ms)
    ✓ Should use Node 12 as runtime (7459 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        22.211 s
Ran all test suites.

Environment

  • CDK CLI Version: 1.62
  • Module Version: 1.62
  • Node.js Version: v14.4.0
  • OS: OSX Catalina
  • Language (Version): TypeScript 4.0.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:27 (22 by maintainers)

github_iconTop GitHub Comments

15reactions
jogoldcommented, Nov 2, 2020

@floydspace we are going to replace parcel with esbuild while still maintaining local bundling + fallback to Docker approach for the moment. People installing esbuild will have very fast bundling performances.

Let me first draft a PR for this then we can work on it together.

9reactions
floydspacecommented, Oct 28, 2020

Hey @jaapvanblaaderen . I have implemented a new cdk construct aws-lambda-nodejs-esbuild

See comparison results on my machine: @aws-cdk/aws-lambda-nodejs:

Bundling asset simple-stack/HandlerLambda/Code/Stage...

 RUNS  lib/simple-stack.test.ts
✨ Built in 11.88s

 PASS  lib/simple-stack.test.ts (84.678 s)s/_qq218h940s33jg73wss4k5w0000gn/T/cdk.outeeruBW/bundling-temp-dc2901b128dbc7ef10d25ae6a7a15a98d5e3ac81c654c3ad726474eee5ec  Simple Stack
    ✓ Should have memory size set to 512MB (13909 ms)
    ✓ Should use Node 12 as runtime (67285 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        86.375 s, estimated 133 s
Ran all test suites.

vs aws-lambda-nodejs-esbuild:

 PASS  lib/simple-stack.test.ts
  Simple Stack
    ✓ Should have memory size set to 512MB (127 ms)
    ✓ Should use Node 12 as runtime (50 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        2.045 s, estimated 4 s
Ran all test suites.

I forked your sample, so you can see how to migrate

Just saying.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimizing Node.js dependencies in AWS Lambda
This post shows how to bundle and minify Lambda function code to optimize performance and stay up to date with the latest version...
Read more >
3 Major Ways To Improve AWS Lambda Performance
Improve Lambda performance by understanding Lambda cold starts, Lambda time outs, and slow Lambda response times.
Read more >
AWS CDK - aws-lambda-nodejs Module (updated)
Due to the Docker-in-Docker and other performance issues, we elected not to use aws-lambda-nodejs for our stack but instead bundle ...
Read more >
aws-cdk/aws-lambda-nodejs - npm package
The npm package @aws-cdk/aws-lambda-nodejs was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as ......
Read more >
Bundling your Node.js app for AWS Lambda
In such a case, it is actually beneficial that large string assets are slowing down Pulumi CLI performance. Slow CLI reminds you that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found