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

Stop Sam Local from rebuilding layers on every invoke #3725

Open
ahurlburt opened this issue Mar 12, 2022 · 16 comments
Open

Stop Sam Local from rebuilding layers on every invoke #3725

ahurlburt opened this issue Mar 12, 2022 · 16 comments
Labels
area/local/start-api sam local start-api command maintainer/need-followup type/feature Feature request

Comments

@ahurlburt
Copy link

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: Envek/aws-sam-typescript-layers-example#11 (comment) 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?

@torresxb1
Copy link
Contributor

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: #3725). To make sure I understand, is this feature request for only building layers when changes are detected?

@ahurlburt
Copy link
Author

ahurlburt commented Mar 23, 2022

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

@timhaines
Copy link

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

@risurina
Copy link

risurina commented Aug 9, 2022

+1

@danros
Copy link

danros commented Nov 15, 2022

+1

@astroanu
Copy link

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

@sebelga
Copy link

sebelga commented Feb 5, 2023

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... :/

@dschiavu
Copy link

+1

2 similar comments
@HVKukkonen
Copy link

+1

@royassis
Copy link

+1

@ahurlburt
Copy link
Author

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

@konstantinj
Copy link

just came across this. current behaviour sucks.
+1

@ahurlburt
Copy link
Author

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

@CeccoCQ
Copy link

CeccoCQ commented Oct 2, 2023

+1

@sainijagjit
Copy link

+1

@sainijagjit
Copy link

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

It resolved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/start-api sam local start-api command maintainer/need-followup type/feature Feature request
Projects
None yet
Development

No branches or pull requests