Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SAM Local Lambda invocations slow

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?

like image 792
alayor Avatar asked Dec 23 '22 16:12

alayor


1 Answers

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

like image 143
alayor Avatar answered Jan 10 '23 17:01

alayor