Difficult and inconvenience in working with ruby and bundle gems
See original GitHub issueDescription
Here is an example of ruby folder structure
sam-app/ |-- api/ | |-- v1/ | | |-- endpoint.rb | | |-- helper.rb | | |-- helper2.rb |-- template.yaml |-- Gemfile |-- Gemfile.lock |-- vendor/ | |-- bundle/
endpoint.rb
snippet:
require 'rubygems'
require 'bundler/setup'
require_relative 'helper'
def lambda_handler(event:, context:)
end
helper.rb
snippet:
require_relative 'helper2'
helper2.rb
snippet:
require 'some_legit_gem'
without using sam, pure ruby structure, it’s possible to run the code with command below
bundle install --path vendor/bundle
ruby app/v1/endpoint.rb
Steps to reproduce
bundle install # create vendor/bundle at root folder which is good
sam build
sam local start-api
Observed result
{
"errorType": "Init\u003cLoadError\u003e",
"errorMessage": "cannot load such file -- some_legit_gem",
"stackTrace": [
"/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'",
"/var/lang/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'",
Expected result
Doesn’t require vendor/bundle
to be same level as actual lambda handler or provide a simple entry point to lookup vendor folder
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Mac OS 10.14.6
- Sam CLI: 0.22.0:
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Difficult and inconvenience in working with ruby and bundle ...
As a short-term workaround, I strongly suspect that if you put your Gemfile into the api/ folder and just run sam build ,...
Read more >The best way to manage a Ruby application's gems - Bundler
Bundler makes sure that Ruby can find all of the gems in the Gemfile (and all of their dependencies). If your app is...
Read more >openSUSE:Ruby Gem Strategies
Strategies for packaging Ruby gems on openSUSE · Package each gem inside its own rpm · Bundle all gems required for an application...
Read more >Huobi Pro Websocket Api
Add this line to your application's Gemfile: gem 'huboi_api' And then execute: $ bundle Or install it yourself as: $ gem install huboi_api....
Read more >How to Use Bundler To Manage Ruby Gems - Atlantic.Net
This growth can pose problems when gems install their dependencies. If two gems rely upon different versions of the same library, then ...
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
Alternatively, you can
sam build -m Gemfile
from the root directory of your project and it should use the base directory Gemfile for all functions. Let me know if that helps in your case.Closing for now as the base question is answered, feel free to reopen if you have further issues or questions.
So here’s the breakdown of what’s going on:
sam build
looks in theCodeUri
directory for the function given. This is useful in the case where different functions have different dependencies, to keep the overall artifact size down. So it will generally expect theGemfile
to be there, though workarounds exist.sam local
issue where code changes aren’t reflected without building is a known issue and not Ruby specific - you’ve got the workaround and it’s in the feature backlog to have an easier path forward on this.