aws / aws/aws-cdk

lambda: allow bundling of lambda layer

Open
#26,332 10 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda 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

We are missing the bundling functionality when creating `LayerVersion`s in the CDK v2.

### Use Case

We have a lambda layer that uses imports from sibling/root folders (let say a shared util folder in root), but since they will not be included in the same output folder as the layer, these imports will be missing in runtime.
The same goes for node_modules. The modules used would have to be part of the assets target folder.
Bundling the layer takes care of this issue by making sure the imports are included in the bundle.
It also just includes the modules use since esbuild offers some treeshaking.

### Proposed Solution

Offer the same bundling as the NodeJsFunction (also requested for Lambda @ Edge here: https://github.com/aws/aws-cdk/issues/14215).

### Other Information

_No response_

### Acknowledgements

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

### CDK version used

2.87.0

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

Windows 10 x64. Node 18.12.x.

Contributor guide

Open the contributing guide

Research direction

Start by comparing the requested LayerVersion behavior with the existing NodeJsFunction bundling support. Trace how layer assets and imports from sibling folders, root folders, and node_modules are handled, then verify that the resulting layer includes the required imports while retaining esbuild tree-shaking.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
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.