serverless-ruby-layer icon indicating copy to clipboard operation
serverless-ruby-layer copied to clipboard

Ruby 3.2 Gem Path Error for AWS SDK

Open jaredSiebert opened this issue 9 months ago • 2 comments

AWS Lambda with Ruby 3.2 error - by setting the GEM_PATH environment variable, the native aws-sdk gems cannot load

{
  "errorMessage": "cannot load such file -- aws-sdk-dynamodb",
  "errorType": "Init<LoadError>",
  "stackTrace": [
    "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:136:in `require'",
    "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:136:in `require'",
    "/var/task/handler.rb:1:in `<top (required)>'",
    "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:136:in `require'",
    "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:136:in `require'"
  ]
}

Additional context As outlined in AWS docs for including gems from layers (https://docs.aws.amazon.com/lambda/latest/dg/ruby-package.html#ruby-package-dependencies-layers), if the generated zip file structure changes from ruby/3.2.0/* to ruby/gems/3.2.0/* then there is no need to set the GEM_PATH environment variable which will eliminate the issue of the native aws-sdk gems not being found.

Confirmed this works by compiling the deploy_http_nokogiri sample (https://navarasu.github.io/serverless-ruby-layer/#/use_docker), unzipping gemLayer.zip and adjusting the folder structure, zipping and manually uploading a custom layer to AWS.

jaredSiebert avatar May 23 '24 16:05 jaredSiebert