(aws-cloudfront): Support bundling code for CloudFront Functions
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
### Describe the feature
Support running the code for CloudFront Functions (not Lambda@Edge) through esbuild and/or tsc.
### Use Case
- Bundle in modules, particularly polyfills
- Minify and treeshake to help keep within the default 10k limit for CloudFront Functions
- Removing comments
- Transpile down to the limited JavaScript supported for CloudFront Functions
- Type checking to detect errors early
- Assist with converting Lambda@Edge functions to cheaper CloudFront Functions
### Proposed Solution
- Add AssetCode and AssetCodeOptions to packages/aws-cdk-lib/aws-cloudfront/lib/function.ts.
- AssetCode provides a render method that emits the output from running the function code through esbuild and/or tsc. Perhaps reusing the mechanism aws_lambda_nodejs.AssetCode uses.
- Add the static method FunctionCode.fromAsset(path, options) to construct AssetCode, paralleling aws_lambda_nodejs.Code.fromAsset(path, options)
- Provide two pre-configured bundling options: one that targets JavaScript Function runtime 1.0 and one that targets runtime 2.0
### 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.144.0
### Environment details (OS name and version, etc.)
NodeJS/iron
Contributor guide
Research direction
Start in packages/aws-cdk-lib/aws-cloudfront/lib/function.ts and compare the proposed AssetCode and FunctionCode.fromAsset APIs with aws_lambda_nodejs.AssetCode. Review the esbuild and/or tsc bundling mechanism mentioned in the issue, then determine how runtime 1.0 and 2.0 options should be represented. Done means CloudFront Function code can be bundled, minified, treeshaken, and transpiled through the proposed API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100