-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from navarasu/fix_36_requires_all
#36 Added example and test for bundler.require all. Include Gemfile and Gemfile.lock in package if lock file is present
- Loading branch information
Showing
12 changed files
with
199 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
|
||
## Using `Bundler.require(:default)` to require all gems in handler.rb by respecting Gemfile.lock | ||
|
||
<!-- tabs:start --> | ||
|
||
#### ** handler.rb ** | ||
|
||
```ruby | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
Bundler.require(:default) | ||
|
||
def hello(event:, context:) | ||
body = HTTP.get('https://github.com').body.to_s | ||
doc = Nokogiri::HTML(body) | ||
|
||
{ statusCode: 200, body: doc.title } | ||
end | ||
|
||
|
||
``` | ||
|
||
#### ** serverless.yml ** | ||
|
||
```yml | ||
service: bundler_require_all | ||
|
||
plugins: | ||
- serverless-ruby-layer | ||
|
||
custom: | ||
rubyLayer: | ||
use_docker: true | ||
|
||
provider: | ||
name: aws | ||
runtime: ruby2.5 | ||
|
||
functions: | ||
hello: | ||
handler: handler.hello | ||
|
||
``` | ||
|
||
#### ** Gemfile ** | ||
|
||
```ruby | ||
source 'https://rubygems.org' | ||
gem 'http' | ||
gem 'nokogiri' | ||
``` | ||
|
||
#### ** Gemfile.lock ** | ||
|
||
```ruby | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
httparty (0.18.1) | ||
mime-types (~> 3.0) | ||
multi_xml (>= 0.5.2) | ||
mime-types (3.3.1) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2020.1104) | ||
mini_portile2 (2.5.1) | ||
multi_xml (0.6.0) | ||
nokogiri (1.11.3) | ||
mini_portile2 (~> 2.5.0) | ||
racc (~> 1.4) | ||
racc (1.5.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
httparty | ||
nokogiri | ||
|
||
BUNDLED WITH | ||
2.1.4 | ||
``` | ||
|
||
<!-- tabs:end --> | ||
|
||
|
||
#### Checkout above Example here | ||
|
||
|
||
```bash | ||
git clone https://github.com/navarasu/serverless-ruby.git | ||
``` | ||
```bash | ||
cd serverless-ruby/bundler_require_all | ||
|
||
sls plugin install -n serverless-ruby-layer | ||
|
||
``` | ||
|
||
#### Deploy to AWS | ||
|
||
```bash | ||
sls deploy | ||
``` | ||
|
||
Running `sls deploy` automatically deploys the required gems as in Gemfile to AWS lambda layer and make the gems available to the `RUBY_PATH` of the functions `hello.handler` | ||
|
||
|
||
#### Test it | ||
|
||
```bash | ||
sls invoke -f hello | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
gem 'httparty' | ||
gem 'nokogiri' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
httparty (0.18.1) | ||
mime-types (~> 3.0) | ||
multi_xml (>= 0.5.2) | ||
mime-types (3.3.1) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2020.1104) | ||
mini_portile2 (2.5.1) | ||
multi_xml (0.6.0) | ||
nokogiri (1.11.3) | ||
mini_portile2 (~> 2.5.0) | ||
racc (~> 1.4) | ||
racc (1.5.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
httparty | ||
nokogiri | ||
|
||
BUNDLED WITH | ||
2.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
Bundler.require(:default) | ||
|
||
def hello(event:, context:) | ||
body = HTTParty.get("https://github.com").body | ||
doc = Nokogiri::HTML(body) | ||
|
||
{ statusCode: 200, body: doc.title } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
service: bundler-require-all | ||
|
||
plugins: | ||
- serverless-ruby-layer | ||
provider: | ||
name: aws | ||
runtime: ruby2.5 | ||
|
||
custom: | ||
rubyLayer: | ||
use_docker: true | ||
|
||
functions: | ||
hello: | ||
handler: handler.hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters