Build cache should exclude `.aws-sam` in md5 calculation
See original GitHub issueDescription:
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?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
sam build - AWS Serverless Application Model
Enable or disable cached builds. Use this option to reuse build artifacts that haven't changed from previous builds. AWS SAM evaluates whether you've...
Read more >Working with layers - AWS Serverless Application Model
The AWS SAM CLI generates the names of the images it builds, as well as the LayerVersions that are held in the cache....
Read more >MD5 function - Amazon Redshift - AWS Documentation
The MD5 function returns a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum. Examples. The following...
Read more >Accelerating serverless development with AWS SAM Accelerate
Building a serverless application changes the way developers think about testing their code. Previously, developers would emulate the ...
Read more >Api - AWS Serverless Application Model - AWS Documentation
Creates a collection of Amazon API Gateway resources and methods that can be invoked through HTTPS endpoints.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh that’s why, thanks for providing the information. As a workaround, you can continue to use
-b
option or put the source code into a subfolder and set aCodeUri
to<sub-folder-name>
.⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.