Description:
When using SAM to build a Ruby layer, packaging of Gems is incorrect. Gems are bundled in ruby /lib/vendor/bundle/ruby/2.7.0 using the default bundler workflow, these Gems are not picked up by the runtime.
Per documentation, GEM_PATH (ruby/gems/2.7.0) should be used. Shared / custom code is packaged properly to RUBYLIB (ruby/lib).
Steps to reproduce the issue:
- Create new SAM application.
- Add Layer to template:
SAMBuildLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: SAMBuild
CompatibleRuntimes:
- ruby2.7
Metadata:
BuildMethod: ruby2.7
- Add directory
SAMBuild containing a Gemfile with valid contents.
- Run
sam build command.
- Review results and/or test with a sample function.
Observed result:
Result of build (.aws-sam/build) contains SAMBuildLayer/ruby/lib/vendor/bundle/ruby/2.7.0/gems with bundled Gems. When attempting to run sample function, Gem is not found.
Expected result:
Gem should be packaged in ruby/gems/2.7.0 and available to function when executed. I was able to build using a Makefile:
MakeBuildLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: MakeBuild
CompatibleRuntimes:
- ruby2.7
Metadata:
BuildMethod: makefile
And Makefile in MakeBuild directory:
build-MakeBuildLayer:
bundle install --path=$(ARTIFACTS_DIR)
rm -rf $(ARTIFACTS_DIR)/ruby/2.7.0/cache && rm -rf $(ARTIFACTS_DIR)/ruby/2.7.0/bin
mkdir $(ARTIFACTS_DIR)/ruby/gems
mv $(ARTIFACTS_DIR)/ruby/2.7.0 $(ARTIFACTS_DIR)/ruby/gems
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
SAM CLI, version 0.52.0
Description:
When using SAM to build a Ruby layer, packaging of Gems is incorrect. Gems are bundled in
ruby /lib/vendor/bundle/ruby/2.7.0using the default bundler workflow, these Gems are not picked up by the runtime.Per documentation,
GEM_PATH(ruby/gems/2.7.0) should be used. Shared / custom code is packaged properly toRUBYLIB(ruby/lib).Steps to reproduce the issue:
SAMBuildcontaining aGemfilewith valid contents.sam buildcommand.Observed result:
Result of build (
.aws-sam/build) containsSAMBuildLayer/ruby/lib/vendor/bundle/ruby/2.7.0/gemswith bundled Gems. When attempting to run sample function, Gem is not found.Expected result:
Gem should be packaged in
ruby/gems/2.7.0and available to function when executed. I was able to build using a Makefile:And Makefile in
MakeBuilddirectory:Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
SAM CLI, version 0.52.0