Bug: sam package does not vendor Gems if --template-file is passed
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description:
`sam package` correctly includes vendored RubyGems if the `--template-file` argument is omitted and the default (template.yaml) is used. However, if you specify `--template-file template.yaml` explicitly, a package is generated and uploaded, but it does not include vendored gems, leading to runtime failures when gems are missing or do not match the version locked in Gemfile.lock.
### Steps to reproduce:
1. `sam init --app-template hello-world --runtime ruby3.3 --no-tracing --no-application-insights --no-structured-logging --package-type Zip`
2. `sam build && sam package --template-file template.yaml`
[logs.txt](https://github.com/user-attachments/files/17805862/logs.txt)
### Observed result:
If you run `aws s3 cp s3://aws-sam-cli-managed-default-samclisourcebucket-t3venr6as008/530d0f91bb545a27febc4651f7d0e701 packaged.zip` to download the package and `unzip -l packaged.zip` you can see that only the source files are present:
```
Archive: packaged.zip
Length Date Time Name
--------- ---------- ----- ----
1126 1980-01-01 00:00 app.rb
61 1980-01-01 00:00 Gemfile
--------- -------
1187 2 files
```
### Expected result:
If you omit `--template-file template.yaml`, everything works as expected and the uploaded Zip package contains the vendored gems:
```
unzip -l packaged-no-template.zip
Archive: packaged-no-template.zip
Length Date Time Name
--------- ---------- ----- ----
352 1980-01-01 00:00 Gemfile.lock
1126 1980-01-01 00:00 app.rb
61 1980-01-01 00:00 Gemfile
1288 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/specifications/httparty-0.22.0.gemspec
1233 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/specifications/multi_xml-0.7.1.gemspec
1205 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/specifications/bigdecimal-3.1.8.gemspec
1201 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/specifications/mini_mime-1.1.5.gemspec
1811 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/specifications/csv-3.3.0.gemspec
1060 1980-01-01 00:00 vendor/bundle/ruby/3.3.0/gems/multi_xml-0.7.1/LICENSE.md
```
I don't see anything in the `--help` for `sam package` that would indicate why explicitly specifying the template file would cause such a dramatic difference in behavior. Am I missing something? Thank you!
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: Linux 6.10.11-amd64 # 1 SMP PREEMPT_DYNAMIC Debian 6.10.11-1 (2024-09-22) x86_64 GNU/Linux
4. `sam --version`: SAM CLI, version 1.129.0
5. AWS region: us-east-1
# Paste the output of `sam --info` here
```
{
"version": "1.129.0",
"system": {
"python": "3.11.10",
"os": "Linux-6.10.11-amd64-x86_64-with-glibc2.40"
},
"additional_dependencies": {
"docker_engine": "26.1.5+dfsg1",
"aws_cdk": "Not available",
"terraform": "1.6.3"
},
"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"
]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.