aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

CLI parameter to avoid rebuilding container on every request

Open helephant opened this issue 7 years ago • 3 comments

We run SAM on our local developer machines to execute a visual regression test on a lambda process that generates images. It's fantastic being able to emulate the lambda environment without pushing the code to AWS. However, as our test suite grows, we are finding that the tests are very slow (around 15-20 seconds each).

When we look at the output logs, it looks like it builds and mounts the image for every request:

Invoking src/theLambda.handler (nodejs8.10)
2019-11-28 12:32:33 Found credentials in environment variables.
ChromiumLayer is a local Layer in the template
Building image...
Requested to skip pulling images ...

Mounting /code/theproject as /var/task:ro,delegated inside runtime container
START RequestId: 7ebf8ec4-f623-10ce-d545-ff8132f04fab Version: $LATEST
END RequestId: 7ebf8ec4-f623-10ce-d545-ff8132f04fab
REPORT RequestId: 7ebf8ec4-f623-10ce-d545-ff8132f04fab	Init Duration: 2922.02 ms	Duration: 3436.73 ms	Billed Duration: 3500 ms	Memory Size: 1792 MB	Max Memory Used: 73 MB	

We invoke SAM using sam local start-lambda -p 8035 --skip-pull-image.

That's very helpful behaviour for development, but makes our tests extremely slow. Would it be possible to have a command line switch to avoid this so we can speed our tests up?

helephant avatar Nov 28 '19 12:11 helephant

Transferring to SAM CLI repo

jlhood avatar Dec 03 '19 16:12 jlhood

@helephant Thanks for the issue. This building only happens for layers that are locally referenced in your template, ChromiumLayer is a local Layer in the template. We do this to ensure any change is reflected in the container. If you do not wish for this, the current option is to publish the layer to the Lambda Service and reference it through the ARN instead or a Ref: LambdaLayerResource.

Additionally, I wouldn't really recommend what you are using the CLI for. Instead of running your automated tests against the CLI, you should be deploying this to an account and testing on the actually service. This gives you full fidelity and ensures your service will work as you expected. The CLI is a re-implementation and therefore there may be gaps between what the CLI has and what the service offers.

jfuss avatar Dec 03 '19 17:12 jfuss

Thank you very much for your reply. That is very helpful and we will try this out.

We are actually doing both: our build pipeline tests against the real environment but we are also running the tests on our local machines because of the slow feedback loop when deploying things to AWS.

helephant avatar Dec 03 '19 21:12 helephant