Error when running a lambda using a custom AWS lambda layer for Ruby 3.2.0

0

Good day,

I have a lambda running on Ruby 3.2. It is going to perform database operations to RDS (Postgresql) via PG gem.

I have created a lambda layer as per this step: https://docs.aws.amazon.com/lambda/latest/dg/ruby-package.html#ruby-package-dependencies

But it shows an error when running:

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

I followed the file structure for Ruby.

 pg.zip
 └ ruby/gems/3.2.0/
               | build_info
               | cache
               | doc
               | extensions
                  └ pg-1.5.3
               | gems
                  └ pg-1.5.3.gemspec

I made sure the version is the same.

Simple lambda to reproduce the error:

require 'json'
require 'pg'

def lambda_handler(event:, context:)
       { statusCode: 200, body: JSON.generate('Hello from Lambda!') }
end

Any ideas on how to fix the error?

asked 10 months ago167 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions