AWS SAMでLambdaを動かそうとした時、以下のエラーが出たため修正した。
M1だと発生するのかもしれない。
$ sam local invoke HelloWorldFunction --event events/event.json
Invoking app.lambda_handler (ruby2.7)
Local image was not found.
Removing rapid images for repo public.ecr.aws/sam/emulation-ruby2.7
Building image...................................................................................................................................................................................................................................
Using local image: public.ecr.aws/lambda/ruby:2.7-rapid-arm64.
Mounting /Users/xxx/Develop/environment/xxx/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 97ccf28f-352a-4c64-883f-7687591f6825 Version: $LATEST
ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system
with an unsupported version of glibc.
/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so) - /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so
If that's the case, then please install Nokogiri via the `ruby` platform gem:
gem install nokogiri --platform=ruby
or:
bundle config set force_ruby_platform true
Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.
Init error when loading handler app.lambda_handler
{
"errorMessage": "/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so) - /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `require_relative'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `require_relative'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `<top (required)>'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `rescue in require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:152:in `require'",
"/var/task/app.rb:3:in `<top (required)>'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'"
]
}
16 Feb 2023 12:03:38,157 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 252 InvokeID=
ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system
with an unsupported version of glibc.
/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so) - /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so
If that's the case, then please install Nokogiri via the `ruby` platform gem:
gem install nokogiri --platform=ruby
or:
bundle config set force_ruby_platform true
Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.
Init error when loading handler app.lambda_handler
{
"errorMessage": "/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so) - /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `require_relative'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `require_relative'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `<top (required)>'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `rescue in require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:152:in `require'",
"/var/task/app.rb:3:in `<top (required)>'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'",
"/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'"
]
}
{"errorMessage":"/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so) - /var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/2.7/nokogiri.so","errorType":"Init<LoadError>","stackTrace":["/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `require_relative'","/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri/extension.rb:7:in `<top (required)>'","/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `require_relative'","/var/task/vendor/bundle/ruby/2.7.0/gems/nokogiri-1.14.2-aarch64-linux/lib/nokogiri.rb:8:in `<top (required)>'","/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `require'","/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:162:in `rescue in require'","/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:152:in `require'","/var/task/app.rb:3:in `<top (required)>'","/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'","/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:88:in `require'"]}END RequestId: 043a3453-ce0f-430c-a865-f9432b943106
REPORT RequestId: 043a3453-ce0f-430c-a865-f9432b943106 Init Duration: 0.06 ms Duration: 516.77 ms Billed Duration: 517 ms Memory Size: 128 MB Max Memory Used: 128 MB
回避方法
$ cd hello_world
$ bundle config set force_ruby_platform true
実際に見るGemfileはrootではなくhello_world配下なので注意。