aws / aws/aws-cdk

aws-cdk-lib/aws-lambda-nodejs: cache esbuild results

Open
#26,020 23 comments 32 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
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

The `NodejsFunction` construct should intelligently cache build results of esbuild and reuse them on subsequent deploys.

```ts
new NodejsLambda(this, "CachedNodejsLambda", { bundling: { cache: true } });
```

### Use Case

When working on a CDK app with many lambdas, deployments can take longer than I'd like. I want this to be faster so that the CDK provides a better DX and faster deployments. Work smarter, not harder, right? ;)

### Proposed Solution

1. Use [es-module-lexer](https://github.com/guybedford/es-module-lexer) to find all files imported by entry point file.
2. Compute hash of those files.
3. Use hash for `bundling.assetHash` of construct
4. Enjoy faster synths/deployments!

Technical considerations:
- Ensure source code from local workspaces (like PNPM) that change are included in hash

### Other Information

If this is out of scope of the AWS CDK (which I hope it is not), @NimmLorr has documented a solution using turbopack. See [this comment](https://github.com/aws/aws-cdk/issues/24456#issuecomment-1574158364).

### Acknowledgements

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

### CDK version used

N/A

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

N/A

Contributor guide

Open the contributing guide

Research direction

Start by locating the NodejsFunction construct and the bundling.assetHash implementation. Review how es-module-lexer would identify imported files, including local workspace sources such as PNPM dependencies. Done means unchanged inputs reuse esbuild results while changes to imported or workspace files invalidate the cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
build-system, cloud, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.