Support BuildProperties/BuildMethod config for multiple functions
Describe your idea/feature/enhancement
Hey folks, super pumped about the new typescript + esbuild feature. One annoying thing I noticed is that for every function resource, I have to specify a metadata field with the esbuild options. You can imagine how repetitive this can get with multiple functions.
e.g.
Metadata: # Manage esbuild properties
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: 'es2020'
Sourcemap: true
EntryPoints:
- index.ts
Proposal
Would be awesome if we could somehow add this to the Globals section of the sam template. e.g If I wanted to use esbuild for all my functions.
The same would be great to have for LayerVersion.
@iRoachie Thanks for the feature request. Globals happens as apart of the SAM Transform, so I don't think we want to support this locally or in SAM.
However, I do see a need for something like this and what I think you are asking for is to be able to set build args for all your buildable resources similar to how you could do this by using esbuild or other tooling (either in the command line or rc files.). I am not sure the best way to support this though but I do think it is a good improvement.
If the intention is correct above, I will flag this for our PM to review.
I wasn't sure how it could be done, but yes the intent is correct.
Agree, the commonality is needed to be placed in the Globals > Function section, with the exception for EntryPoints. I also believe EntryPoints should THEN be more easily configured inside the Resources portion, because Metadata > BuildProperties > EntryPoints > app.ts is just too lengthy.
Thanks for your feedback.
Since esbuild support is still beta, we will work with our PM to find an alternative way, which should resolve this issue.
Any news on this one? It is stopper for us when it comes to using esbuild.
One workaround is to use yaml anchor merges (name something, then reuse), e.g.
x-anchors:
Metadata: &esb_meta
BuildMethod: esbuild
BuildProperties: &esb_props
Minify: true
Target: es2020
Sourcemap: true
Packages: external
Resources:
FunctionAlpha:
Type: AWS::Serverless::Function
Properties:
FunctionName: func-alpha
Handler: handler.lambdaHandler
Metadata:
<<: *esb_meta
BuildProperties:
<<: *esb_props
EntryPoints:
- handlers/alpha/handler.ts
FunctionBeta:
Type: AWS::Serverless::Function
Properties:
FunctionName: func-beta
Handler: handler.lambdaHandler
Metadata:
<<: *esb_meta
BuildProperties:
<<: *esb_props
EntryPoints:
- handlers/beta/handler.ts
Ignore possible tooling errors saying it's not allowed. SAM CLI 1.95.0 seems to handle it just fine unless you sam validate.
@yegorpetrov How about this? It should works on both sam validate and sam deploy
MetaData: &esbuild_props
Minify: true
Target: es2020
Sourcemap: true
Packages: external
Resources:
FunctionAlpha:
Type: AWS::Serverless::Function
Properties:
FunctionName: func-alpha
Handler: handler.lambdaHandler
Metadata:
BuildMethod: esbuild
BuildProperties:
<<: *esbuild_props
EntryPoints:
- handlers/alpha/handler.ts
@yegorpetrov How about this? It should works on both
sam validateandsam deployMetaData: &esbuild_props Minify: true Target: es2020 Sourcemap: true Packages: external Resources: FunctionAlpha: Type: AWS::Serverless::Function Properties: FunctionName: func-alpha Handler: handler.lambdaHandler Metadata: BuildMethod: esbuild BuildProperties: <<: *esbuild_props EntryPoints: - handlers/alpha/handler.ts
Yes, that's what we ended up with for now.
@yegorpetrov How about this? It should works on both
sam validateandsam deployMetaData: &esbuild_props Minify: true Target: es2020 Sourcemap: true Packages: external Resources: FunctionAlpha: Type: AWS::Serverless::Function Properties: FunctionName: func-alpha Handler: handler.lambdaHandler Metadata: BuildMethod: esbuild BuildProperties: <<: *esbuild_props EntryPoints: - handlers/alpha/handler.tsYes, that's what we ended up with for now.
Metadata, not MetaData