简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM