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

Generic Build Proposal #858

Closed
j opened this issue Dec 13, 2018 · 6 comments
Closed

Generic Build Proposal #858

j opened this issue Dec 13, 2018 · 6 comments
Labels
area/build sam build command stage/needs-investigation Requires a deeper investigation type/feature Feature request type/feedback
Milestone

Comments

@j
Copy link

j commented Dec 13, 2018

Putting a quick list of what was discussed in #samdev.

The builder implementation is great and sam build is exactly what we need. It seems to be missing the ability to go above and beyond typical build solutions. The builder (for node.js) as it stands expects the function code to build for the exact runtime. The issue is that most people use updated versions of node.js (or typescript) and deploy to older node.js runtimes that Lambda supports, as well as a majority of people need more advanced building. Popular tools like https://github.com/zeit/ncc, https://webpack.js.org/, gulp, browserify, babel, etc, etc, help build stuff that can compile down to AWS Lambda specific versions, perform minification, optimize images, etc, etc. It would be great if anyone who uses sam can also build using the tools they wish. We personally use serverless with functions that utilize webpack (react apps), and typescript (tsc -b).

I'm proposing a more generic builder solution for anyone to implement their own build functionality that other Lambda deployment tools have.

Apex Up (https://up.docs.apex.sh/)

Up has an .upignore and up.json file. The up.json file can contain custom build commands:

{
  "name": "app",
  "hooks": {
    "build": "browserify --node app.js > server.js",
    "clean": "rm server.js"
  }
}

Serverless

There are tons of build plugins for serverless (typescript, webpack, browserify, etc, etc)

Sam Proposal

It'd be awesome if we can take from what's been around for a while and that people are used to and implement it. Automated builds is awesome, but not flexible. If each lambda function could contain their own build directions, that'd make it more flexible.

template.yaml

Resources:
    FunctionOne:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: one/
            Build:
                PreBuild: "npm install"
                Build: " npm run build"
                PostBuild: "npm install --production"
                Exclude:
                    - src/**
                    - node_modules/.bin/**
                    - node_modules/foo/.bin/bar
            Handler: one.handler
            Runtime: nodejs8.10
            Events:
                One:
                    Type: Api
                    Properties:
                        Path: /one
                        Method: get
    FunctionTwo:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: two/
            Build:
                PreBuild: "npm install"
                Build: " npm run build"
                PostBuild: "npm install --production"
            Handler: two.handler
            Runtime: nodejs8.10
            Events:
                Two:
                    Type: Api
                    Properties:
                        Path: /two
                        Method: get

OR sam.json & .samignore files contained in the function directory (not preferred)

{
  "scripts": {
    "prebuild": "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install",
    "build": "tsc -b",
    "postbuild": "npm install --production"
  }
}

Example of excluding everything and cherry picking what's needed.. you should be able to do the opposite of this too.

**
!dist/**
!node_modules/**
!.env
!shared/**
node_modules/some-package/.bin/some-large-unneeded-file

You can go even further and look at scripts.build inside of package.json and do this in the NPM builder, but I think keeping it simple would be best.

I'm more in favor with keeping everything inside of template.yaml if possible.

@jfuss jfuss added type/feedback area/build sam build command labels Dec 13, 2018
@jfuss jfuss added this to the SAM Build Backlog milestone Dec 27, 2018
@dhruvsood dhruvsood removed this from the SAM Build Backlog milestone Jan 18, 2019
@whiteshadoww
Copy link

I will switch from SAM to Serverless if this is not returned to the backlog

@awsjeffg awsjeffg added this to the Backlog milestone Aug 19, 2020
@awsjeffg
Copy link

@whiteshadoww as you wish! Although Serverless is also a fine tool and if its features fit your needs better, you should consider it.

It has been quite a while since this issue was created and in the meantime the team added support for using makefiles in sam build, allowing for various kinds of build customization:

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html

@wchengru
Copy link
Contributor

Thanks for this suggestion! We will consider improving our build options to include the feature you mentioned.

@praneetap
Copy link
Contributor

Hello! Just so commenters are aware we have esbuild support in preview, which might solve some of the original commenter's reported issues. To find out more and leave feedback - #3700 Blog post here - https://aws.amazon.com/blogs/compute/building-typescript-projects-with-aws-sam-cli/

@jfuss
Copy link
Contributor

jfuss commented Feb 8, 2023

Our generic builder is Makefile. There might be more things we can do here but in terms of the initial request we solved it through the Makefile builder.

Closing

@jfuss jfuss closed this as completed Feb 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build sam build command stage/needs-investigation Requires a deeper investigation type/feature Feature request type/feedback
Projects
None yet
Development

No branches or pull requests

8 participants