aws-sam-cli: Why are requests so slow?

I installed the package globally

Created a simple template and js file to say hello, copied from samples

Started with sam local start-api

After the first start which downloads the docker images I can fire a request to the server from a browser or command line.

Immediately says invoking index.handler

waits 10 seconds then Then START, END and REPORT.

Whats the gap between Invoke and START, and what can you do to bring that down? Every request that follows the first has the same delay.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 33 (5 by maintainers)

Most upvoted comments

in my case skip pull docker image before 8s after 1.5s

sam local start-api --skip-pull-image

@ztolley, @jugglingcats, do you have AWS credentials configured? If not, see if adding them speeds up your execution time.

Before each execution, sam attempts to gather credentials. If no local credentials are found, it falls back to gathering credentials from ec2 instance metadata, which can take a very long time to fail if you are not running on an ec2 instance.

Are you using a Java Jar for the code? It unzips the jar on every invoke which might be the problem. We need to implement caching of the unzipped folder to make it faster.

For those finding this issue first, also useful is the --warm-containers EAGER flag.

Ref #239

Although I wasn’t suffering delays as bad as other reports, each request was taking over 2s but after setting the --skip-pull-image flag as recommended by @wishdevs it has brought that down to 1s 👍

Looks like this issue is resolved by supplying credentials. I will close the ticket…

@jamescgibson , The requests are still slow even after setting credential and passing --profile argument. Requests to actual api gateway server is faster than hitting local server.

Just adding to this issue for future searchers: If you configured your credentials with a profile, as of sam v0.2.2, you need to pass --profile <profile_name> to use them.

This allowed me to get the speedups described in this thread.

I am facing the same issue. Everytime url is hit, it says “Decompressing …jar” and it waits for 5 to 8 seconds. I have also set ENV variables, but it is still slow.