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