I am testing a very basic service (based on https://github.com/serverless/examples/tree/v3/aws-ruby-simple-http-endpoint) using the serverless-ruby-package. It's been working perfectly as I carefully add more of my requirements to it. Execution started failing as soon as I added the gem 'mysql2' to the Gemfile. Here is the error in Cloudwatch:
{
"errorMessage": "libmariadb.so.3: cannot open shared object file: No such file or directory - /var/task/vendor/bundle/ruby/3.2.0/gems/mysql2-0.5.6/lib/mysql2/mysql2.so",
"errorType": "Init",
"stackTrace": [
"internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:37:in require'", "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in require'",
"/var/task/vendor/bundle/ruby/3.2.0/gems/mysql2-0.5.6/lib/mysql2.rb:36:in <top (required)>'", "<internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in require'",
"internal:/var/lang/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:37:in require'", "/var/task/handler.rb:2: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'"
]
}
The mysql2.so file was built within the image and is present in the Docker image, in the vendor/ files, and is visible in the AWS Lambda console "Code" tab. Rebuilding the gems with Ruby 3.3 and deploying with the 3.3 Docker image also resulted in the same problem.
Serverless.yml excerpt:
service: er-ops
frameworkVersion: "3"
provider:
name: aws
runtime: ruby3.2
plugins:
- serverless-ruby-package
functions:
call_count:
handler: handler.call_count
environment:
RDS_DB_NAME: ${ssm:/database/name}
RDS_HOSTNAME: ${ssm:/database/host}
RDS_HOSTNAME_READER: ${ssm:/database/host_reader}
RDS_PASSWORD: ${ssm:/database/password}
RDS_USERNAME: ${ssm:/database/username}
events:
- httpApi:
path: /call-count
method: get
package:
include:
- handler.rb
Environment:
Docker Image (command "docker image ls"): amazon/aws-lambda-ruby 3.2 3f8c5310dbf8 11 days ago 683MB
Ruby: RVM using Ruby 3.2.3
I am testing a very basic service (based on https://github.com/serverless/examples/tree/v3/aws-ruby-simple-http-endpoint) using the serverless-ruby-package. It's been working perfectly as I carefully add more of my requirements to it. Execution started failing as soon as I added the
gem 'mysql2'to the Gemfile. Here is the error in Cloudwatch:The mysql2.so file was built within the image and is present in the Docker image, in the vendor/ files, and is visible in the AWS Lambda console "Code" tab. Rebuilding the gems with Ruby 3.3 and deploying with the 3.3 Docker image also resulted in the same problem.
Serverless.yml excerpt:
Environment:
Docker Image (command "docker image ls"): amazon/aws-lambda-ruby 3.2 3f8c5310dbf8 11 days ago 683MB
Ruby: RVM using Ruby 3.2.3