Build identical artifacts only once#1180
Build identical artifacts only once#1180Dunedan wants to merge 1 commit intoaws:developfrom conhealth:speed-up-sam-build
Conversation
Previously when running `sam build` one artifact would be built per AWS Serverless Function. That caused the same artifacts getting built over and over again during a single build build, when multiple AWS Serverless Functions shared the same runtime and CodeUri. With this commit, instead of building one artifact per AWS Serverless Function, one is built for every combination of runtime and CodeUri present in the SAM template. This speeds up the build time dramatically when multiple functions share the same runtime and CodeUri.
|
Seems like fixing the integration tests would be some more effort, especially as there is no 1:1 mapping between function and artifacts anymore. I'm open to suggestions how to approach that best. |
|
Can you explain the usecase here? if they are just the same functions. Cant you define once and !Ref it. |
|
While the functions share the same runtime and CodeUri, they don't share the same handler. Other details like events, memory settings, etc. might differ as well. So it's not the same function which could be re-used throughout the template. The use case are artifacts which contain the code for multiple functions. |
|
@Dunedan Hey this is a great start! I there are a few nuances that needs more thought & iteration:
Would you mind updating the Thoughts? |
|
Sounds great, but it might take a bit until I find time to get to it. 👍 |
|
@thesriram could you elaborate on your !Ref from other functions ? can you use !Ref for codeuri? @Dunedan have you tried using layers? I wanted to explore that to see if it would help at all, since all of my functions have shared/similar artifacts. |
|
I would be interested for this implementation to separate the build of a CodeUri from its eventual existence as a function-named directory under |
Can you describe this more in depth? This PR might not be the right place to discuss, maybe in #1236, but am interested in what you are trying to solve. |
|
I thought I had an issue open for it, but I am not able to find it if I do (I think potentially it's even a Lambda API request, but SAM CLI could solve it client-side). I have opened #1257 for this. |
|
We do want to enable this support but this needs further design before we can accept. For anyone finding this, we would encourage a design doc PR so that we can understand the change before implementing. Closing this as we cannot accept in the current state. |
Previously when running
sam buildone artifact would be builtper AWS Serverless Function. That caused the same artifacts getting
built over and over again during a single build build, when multiple AWS
Serverless Functions shared the same runtime and CodeUri.
With this commit, instead of building one artifact per AWS Serverless
Function, one is built for every combination of runtime and CodeUri
present in the SAM template.
This speeds up the build time dramatically when multiple functions share
the same runtime and CodeUri.
Checklist:
make prpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.