AWS Ruby Lambda Layer with Mysql2

Hey there, I’m trying to create a MySQL2 dependency layer for my Ruby 2.7 lambda functions.

I’ve got a Lambda Layer

Ruby2LambdaDepLayer:
  Type: AWS::Serverless::LayerVersion
  Properties:
    LayerName: ruby-2.7-lambda-dependencies
    Description: Dependencies for ruby lambda functions
    ContentUri: ../pt-lambda/rubyLayer2
    CompatibleRuntimes:
      - ruby2.7
    RetentionPolicy: Retain

that I’m using to package up my dependencies, most notably mysql2.

However when I invoke a lambda that uses this layer, I received the dreaded: “libmysqlclient.so.18: cannot open shared object file: No such file or directory - /opt/ruby/gems/2.7.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.so” error.

I’ve confirmed that all necessary .so files live in /opt/lib and the program is able to call the /opt/ruby/gems/2.7.0/gems/mysql2-0.5.3/lib/mysql2.rb file, but it throws that error right after when the file is required.

Not sure what’s going on but could use some guidance, any help is appreciated. thanks!

Hi yutveg, I hit exactly this scenario - packaging all gem dependencies into a lambda layer. The only problem I have is with the library not found by myself - the error is the same as the example. I’ve tried multiple different variations of a custom ruby layer make file but still cannot resolve. Did you find a resolution for this? I’d be grateful if you would share… thanks