Home>

Using Ruby, I create a scraping program and implement it so that it can be executed regularly.
At this stage, we have even created a scraping program.
I'm uploading the created program to Lambda
Unable to require Gem on Lambda. ..
* In the local environment, you can execute it without any problem by entering the command as shown below.

% bundle exec ruby ​​filename

When I run the uploaded program on Lambda, the following error occurs.

START RequestId: ID Version: $LATEST
Init error when loading handler scrap.scrap {
  "errorMessage": "cannot load such file --nokogiri",
  "errorType": "Init<LoadError>",
  "stackTrace": [
    "/var/lang/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in`require'",
    "/var/lang/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in`require'",
    "/var/task/scrap.rb:2:in`<top (required)>'",
    "/var/lang/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in`require'",
    "/var/lang/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in`require'"
  ]
} END RequestId: ID
REPORT RequestId: ID Duration: 2043.89 ms Billed Duration: 2100 ms Memory Size: 128 MB Max Memory Used: 18 MB
Unknown application error occurred
Init<LoadError>
Steps to upload a Ruby file to Lambda ① Zip Ruby file
% zip -r function.zip filename.rb vendor
② Upload the zip file to Lambda
% aws lambda update-function-code --function-name Function name --zip-file fileb: //function.zip
Supplementary information (FW/tool version, etc.)

・ Ruby: 2.7.0

-Gem is installed using "bundle install --path vendor/bundle".

・ The contents of function.zip are as follows.
① scrap.rb
② vendor/bundle/ruby ​​/ 2.7.0
It has a gem inside ②!