Bug: empty '.aws-sam/cache' directory after running sam build --cache
Description:
According to sam cli documentation, the directory where the cache artifacts are stored when --cached is specified. The default cache directory is .aws-sam/cache.
However, in my testing, it seems that the .aws-sam/cache is always empty. Curious what's the purpose of this directory and when would it be non-empty?
Steps to reproduce:
I defined the following template.yaml file. This is the template I use, but I believe any template would work to reproduce this issue.
Transform:
- AWS::Serverless-2016-10-31
Parameters:
Policy:
Type: String
Default: Delete
Resources:
VerificationQueue:
UpdateReplacePolicy: !Ref Policy
DeletionPolicy: !Ref Policy
Type: AWS::SQS::Queue
TriggerFunction:
Type: AWS::Serverless::Function
Properties:
Handler: lambda_function.lambda_handler
Runtime: python3.8
CodeUri: my-lambda-function/
Here is my handler/codeuri setup.
my-lambda-function/
├── lambda_function.py
└── requirements.txt
Now running sam build --cached --beta-features will generates .aws-sam directory.
Observed result:
.aws-sam/cache does not have any content, which is different from what the documentation mentioned.
Expected result:
Expect to see cache artifacts in this directory.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: MacOs Ventura 13.5.2 (22G91)
sam --version: SAM CLI, version 1.98.0- AWS region: us-west-2
{
"version": "1.98.0",
"system": {
"python": "3.8.13",
"os": "macOS-13.5.2-x86_64-i386-64bit"
},
"additional_dependencies": {
"docker_engine": "Not available",
"aws_cdk": "2.89.0 (build 2ad6683)",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
Thanks for creating this issue @GavinZZ
Cached build got updated for some runtimes to run "incremental" build under the hood. The difference is, cached build checks the entire source folder and decides whether it can re-use whatever build in default (or overriden) --cache-folder. Incremental builds are checking the manifest files (package.json for nodejs and requirements.txt for python for instance) and decides whether it needs to re-download dependencies.
However, these runtimes which supports incremental build is not using --cache-folder option, they are always using .aws-sam/deps for now.
I will check with the team about planning the work, and update this issue once we have changes ready.
Similar issue. My cache folder is empty. SAM CLI, version 1.115.0
My build command is as follow:
sam build --cached --parallel --manifest dependencies/nodejs/package.json --config-env dev
Each Lambda gets rebuilt every time. My Lamda functions are in sub folder src/api/ and src/auth.
Any update on this? I'm using Python and the deps folder is being downloaded each time when --cached is used No changes to the manifest file requirements.txt just minor updates to the lambda function itself It's quicker to build without --cached at this point as its not doing the copy to deps but should this be happening?