aws / aws/aws-cdk

aws_lambda_nodejs: exclude node_modules option from sourcemaps

Open
#28,088 4 comments 3 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
74

Description

### Describe the feature

Excluding sourcemaps and shipping them to your third-party provider is great, but for Lambdas using CloudWatch, you have to include them to get meaningful traces.

It is possible to exclude node_modules sourcemaps to drastically save on final zip size.

### Use Case

Reduce lambda cold starts without sacraficing on the sourcemaps for your own code, which should be enough to properly debug in 90% of the cases.

### Proposed Solution

[This](https://github.com/rehanvdm/lambda-template/pull/1/files#diff-04d2b6fafaa8b5cda9a27152003bb174d134e4726449fa36c9dbfe78e146c8deR32) PR shows an improvement from 34K to 2.2K for the sourcemap file.

Esbuild plugins do not work in sync mode, only async. I know we can not do async work in the try bundle, but there are ways around it 😅, using [deasync](https://www.npmjs.com/package/deasync). Yes this is a controversial package and should not be used in any production runtime code, but seeing as this happens on build time, I feel it is an acceptable "risk" worst case the user can disable the flag if there is really an issue.

You can see it in action in this [Gist](https://gist.github.com/rehanvdm/42d6ffa1d0dbd0283352b80182b28199#file-esbuildfunction-ts-L172) I proposed some time ago.

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

-

### Environment details (OS name and version, etc.)

-

Contributor guide

Open the contributing guide

Research direction

Start with the aws_lambda_nodejs bundling and sourcemap entry points, then read the linked example pull request and Gist to understand the proposed behavior. The change is complete when node_modules sourcemaps can be excluded while the user's own sourcemaps remain available for CloudWatch traces, with the relevant build behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.