Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support BuildProperties/BuildMethod config for multiple functions #3713

Open
iRoachie opened this issue Mar 6, 2022 · 8 comments
Open

Support BuildProperties/BuildMethod config for multiple functions #3713

iRoachie opened this issue Mar 6, 2022 · 8 comments
Labels
area/build sam build command area/node-npm type/feature Feature request

Comments

@iRoachie
Copy link
Contributor

iRoachie commented Mar 6, 2022

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.

@jfuss
Copy link
Contributor

jfuss commented Mar 7, 2022

@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.

@jfuss jfuss added area/build sam build command type/feature Feature request labels Mar 7, 2022
@iRoachie
Copy link
Contributor Author

iRoachie commented Mar 7, 2022

I wasn't sure how it could be done, but yes the intent is correct.

@jfuss jfuss changed the title Include Metadata in globals section Support BuildProperties/BuildMethod config for multiple functions Mar 8, 2022
@Pheru1404
Copy link

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.

@mndeveci
Copy link
Contributor

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.

@stagr
Copy link

stagr commented Feb 27, 2023

Any news on this one? It is stopper for us when it comes to using esbuild.

@yegorpetrov
Copy link

yegorpetrov commented Aug 24, 2023

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.

x-anchors

@ruiwei
Copy link

ruiwei commented Sep 19, 2023

@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
Copy link

@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

Yes, that's what we ended up with for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command area/node-npm type/feature Feature request
Projects
None yet
Development

No branches or pull requests

8 participants