-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Description:
Running sam build --cached always reports that the cache is invalid despite no code changes.
Steps to reproduce:
Run sam build --cached twice. The second run doesn't use the cache.
Observed result:
The cache is deemed invalid and not used despite no code changes.
Expected result:
The cache is used when the code isn't changed between builds.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: OS X 10.15.7 (Catalina), Windows 10
sam --version: SAM CLI, version 1.23.0- AWS region: eu-west-1
Problem
The CLI stores the directory hash in .aws-sam/build.toml. This file is also used when calculating the directory hash. Consider this scenario:
- The developer writes some code. The code directory is now in State 1.
- A build is run and it finds that the directory hash in build.toml doesn't equal
hash(State 1) - SAM deems the cache invalid and rebuilds
- At the end of the build SAM saves
hash(State 1)in build.toml - Saving the hash means that the directory is no longer in State 1 but State 2
- The developer changes no code and runs another build
- SAM compares the hash in build.toml - which is
hash(State 1)- and finds it is not equal to the hash of the current state, State 2 - SAM rebuilds again and saves
hash(State 2)in build.toml, which is now in State 3 due to this update - And so on
Workaround
This issue can be worked around by specifying -b, --build-dir DIRECTORY when calling sam build. Specifying a directory outside of the code directory results in SAM using the cache.
Possible Solutions
How do we solve this issue? Would we be able to ignore .aws-sam/build.toml when calculating the hash?
Reactions are currently unavailable