Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

(aws-cloudfront): Support bundling code for CloudFront Functions #30475

Open
2 tasks
SydneyUni-Jim opened this issue Jun 7, 2024 · 3 comments
Open
2 tasks
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@SydneyUni-Jim
Copy link
Contributor

SydneyUni-Jim commented Jun 7, 2024

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

@SydneyUni-Jim SydneyUni-Jim added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 7, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Jun 7, 2024
@pahud
Copy link
Contributor

pahud commented Jun 7, 2024

I guess it's related to #12671 ?

@pahud pahud added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 7, 2024
@SydneyUni-Jim
Copy link
Contributor Author

SydneyUni-Jim commented Jun 7, 2024

It's not related to #12671, at least not directly. That's about Lambda@Edge. This is about CloudFront Functions, two different things.

ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions.html

@SydneyUni-Jim SydneyUni-Jim changed the title (aws-cloudfront): Support bundling function code (aws-cloudfront): Support bundling code for CloudFront Functions Jun 7, 2024
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants
@pahud @SydneyUni-Jim and others