AWS SAM Local Lambda invocations slow
Asked Answered
C

1

13

I'm trying to test my lambda functions locally using the SAM local CLI. I start the API with this command:

sam local start-api --template ./sam-template.yml --host 0.0.0.0 --port 4001

However, every time I call the API the lambda invocation takes a lot of time (4-5 seconds) I assume the docker container is started every time a function is called.

Is there a workaround to this?

Cuyp answered 22/12, 2020 at 22:25 Comment(0)
C
25

You can add this argument to the SAM CLI command:

--warm-containers EAGER

So it would look like this:

sam local start-api  --warm-containers EAGER --template ./sam-template.yml --host 0.0.0.0 --port 4001

This prevents the containers that run the function from starting every time it is invoked by 'warming' them.

This was added from this feature request: https://github.com/aws/aws-sam-cli/issues/239

Cuyp answered 22/12, 2020 at 22:25 Comment(2)
is any flag for sam local invoke?Breeching
This works! My requests went from ~1500ms to about ~60ms. Thank you very much!Lawabiding

© 2022 - 2024 — McMap. All rights reserved.