question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeDependenciesLayer rebuilding on every API request

See original GitHub issue

First of all, thank you @Envek and others for both the great writeup at https://evilmartians.com/chronicles/serverless-typescript-a-complete-setup-for-aws-sam-lambda and for this template repo.

This is my first time using AWS SAM in general, and it’s been tricky with Typescript.

Problem

When running sam local start-api, every request I make to http://127.0.0.1:3000/ triggers a rebuild of the dependency layer.

Steps to reproduce

The first visit will build the image as expected.

When refreshing the browse, based on this comment, I would expect the image not to rebuild since no source code would have changed.

However, on each request, the image appears to be rebuilt with the following log line:

RuntimeDependenciesLayer is a local Layer in the template

The time it takes to rebuild this image makes it difficult to develop my frontend.

The workaround I have right now is to just point my frontend at my dev environment in AWS, but I’d prefer to be able to run both front & backend locally.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
justintilsoncommented, Feb 5, 2022

One way I found that changes this behavior is to include the --warm-containers=EAGER flag when starting your local SAM API. Example:

sam local start-api --docker-network your-network --env-vars=env.json --warm-containers=EAGER

From: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html with some more relevant tidbits here: https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/

0reactions
ahurlburtcommented, Mar 12, 2022

@Envek done: https://github.com/aws/aws-sam-cli/issues/3725

Maybe people coming across this can upvote 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop Sam Local from rebuilding layers on every invoke #3725
Currently it seems that sam local start-api will build any lambda layers on every request. This ends up creating a very slow dev...
Read more >
Using AWS SAM-CLI requires rebuild every time I update the ...
A great solution to this problem is to use the skip-pull-image flag so that Docker will reuse the Lambda runtime. Essentially run:.
Read more >
Working with AWS Lambda and Lambda Layers in AWS SAM
Each runtime then looks for a language-specific folder under the /opt directory. ... To force SAM CLI to rebuild the layer cache, pass...
Read more >
Using layers to manage code dependencies in serverless ...
In this session, I cover using Lambda Layers to manage code dependencies across Lambda functions within an application as well as across ...
Read more >
Caching Dependencies - CircleCI
Restoring cache. CircleCI restores caches in the order of keys listed in the restore_cache step. Each cache key is namespaced to the project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found