aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Allow multiple resources for sam build #3761

Open chizou opened 2 years ago

chizou commented 2 years ago

Describe your idea/feature/enhancement

I'd like to be able to pass multiple resources to sam build, e.g.: sam build layer1 layer2 function1 function2

The main reason I think this would be useful is I have a template that has multiple resources that I want to build individually. I end up having to build one, copy the output, build the other one, copy the output, etc, etc. It'd be nice if I could just specify multiple resources and have one template and set of resources as output.

I also have a large template that takes a while to run sam build against. I can currently specify one resource at a time, but then I can't take advantage of --parallel and it's kind of bulky to have to run the same command multiple times.

Proposal

Things to consider:

  1. Will this require any updates to the SAM Spec I don't think so?
mildaniel commented 2 years ago

Hey @chizou, thanks for the suggestion. I will bring this up to the team, but we always encourage contributions if this is something you'd like to tackle yourself!

chizou commented 2 years ago

@mildaniel , I should have updated my original issue but the workflow I thought I had working actually doesn't even work because the dirs generated are referential. So copying the file breaks the reference. Consequently, I don't think it's actually possible to sam build on a template that has more than one resource you wish to build separately from the rest of the template.

sriram-mv commented 2 years ago

@chizou you can also take advantage of --cached builds if you aren't already this will ensure that other resources that have not been touched are not rebuilt.

bbrummer commented 1 year ago

I'd VERY much like this as well.

Currently I have a huge project that has both Python and Node based functions. --parallel --use-container is flatout broken for Node on our systems. No idea why, but they cause indefinite hangs at the NodejsNpmBuilder:NpmInstall step, those containerized Node builds NEVER FINISH and just sit there. Killing sam doesn't clean them up either...I have to manually go into docker and kill off all the hung containers.

Running in serial (ie, not --parallel) those Node builds do complete correctly...most of the time. They're still prone to hang, but using --parallel they are guartenteed to hang. So we have to run the Node builds in serial.

We could just run the entire build without --parallel...but most of our code is Python that doesn't have any of these issues and without --parallel spinning up each of those containers one at a time takes ages. So we WANT --parallel for the Python code.

We can't take advantage of --parallel without either applying it to the entire build (which breaks because NodejsNpmBuilder:NpmInstall is broken). So we must first peel off the Node functions and run them without --parallel. But since we can't target more than one function at a time without targeting everything, we end up having to call sam build in a loop for each individual Node function which adds considerable startup overhead. Still better than not using --parallel on everything...but not great.

I get it, I'm asking for this feature as a workaround for other SAM bugs. But it seems like a small, obvious thing, that's useful in other context and actually quite surprising it's not already supported.

SAM CLI, version 1.79.0

Linux jenkins4 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Docker version 24.0.0, build 98fdcd7