aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Stop Sam Local from rebuilding layers on every invoke

Open ahurlburt opened this issue 3 years ago • 16 comments

Currently it seems that sam local start-api will build any lambda layers on every request. This ends up creating a very slow dev experience.

Since sam build seems to be able to determine if a layer changes or not the local api behaviour not just assume the layer hasn't changed. If it does change sam build will rebuild it anyway?

it seems like passing the --warm-containers=EAGER as mentioned in this thread: https://github.com/Envek/aws-sam-typescript-layers-example/issues/11#issuecomment-1036057433 stops the layers from building each time but this isn't really a nice solution since a lot of times during testing I want to just test a single lambda I don't want to have to wait for all the lambda's to build layers again (each time I make a change to the code).

Is there another option I'm missing?

ahurlburt avatar Mar 12 '22 00:03 ahurlburt

Thanks for bringing this to our attention! Tagging this as a feature request because it seems like there's a couple of ways to not build on every invoke (using eager warm containers or publishing the layer and referencing the ARN: https://github.com/aws/aws-sam-cli/issues/3725). To make sure I understand, is this feature request for only building layers when changes are detected?

torresxb1 avatar Mar 15 '22 21:03 torresxb1

@torresxb1 - yes that's correct a request to only rebuild layers when changes are detected to the layer. At least in my workflow the layers change very infrequently compared to the lambda source (and it by far takes the longest to build) so rebuilding each time really slows down the dev experience.

You're correct there are workaround as mentioned but both of them have downsides I tried to call out. So I think it would greatly help speed local dev (when using layers) if this was improved.

Finally, and this may just be my lack of understanding but why do they layers have to be rebuilt at all by the running process? When we make code changes to the lambda we need to run sam build for the changes to take effect. build seems to know already when the layer changes so why does the running container decide to rebuild the layers?

Thanks!

ahurlburt avatar Mar 23 '22 19:03 ahurlburt

Does using eager warm containers actually work? I just tried the switch and get errors.

timhaines avatar Jun 09 '22 03:06 timhaines

+1

risurina avatar Aug 09 '22 10:08 risurina

+1

danros avatar Nov 15 '22 13:11 danros

--warm-containers=EAGER doesn't really do the job, as soon as the function code is changed from that point onwards the layer is built on each request.

astroanu avatar Jan 16 '23 22:01 astroanu

This is indeed very annoying. I have my node_modules in a layer and I rarely make any change to them but I have to wait a very long time on each lambda source code change to invoke it. The only workaround that work for me is to deploy the stack and use a fixed arn reference for that layer. But then if I want to add a new dependency i need to do a deploy just for that... :/

sebelga avatar Feb 05 '23 11:02 sebelga

+1

dschiavu avatar Feb 25 '23 00:02 dschiavu

+1

HVKukkonen avatar Mar 10 '23 15:03 HVKukkonen

+1

royassis avatar Apr 24 '23 19:04 royassis

@torresxb1 any updates on this or if it can be implemented. It seems this is effecting quite a few devs. It really slows down process.

ahurlburt avatar May 17 '23 13:05 ahurlburt

just came across this. current behaviour sucks. +1

konstantinj avatar May 24 '23 08:05 konstantinj

@praneetap - is there a list of features somewhere being worked by sam accelerate team? This feature seems to be pretty highly requested and it is brutal to use sam local for dev if the layers keep rebuilding. Nearly all the issues i find related to sam and slowness is related to inefficient layer handling.

ahurlburt avatar May 24 '23 12:05 ahurlburt

+1

CeccoCQ avatar Oct 02 '23 06:10 CeccoCQ

+1

sainijagjit avatar May 17 '24 17:05 sainijagjit

sam local start-api --debug --warm-containers LAZY --skip-pull-image

It resolved the issue

sainijagjit avatar May 17 '24 18:05 sainijagjit