customink / mysql2-lambda Goto Github PK
View Code? Open in Web Editor NEWPrecompiled Mysql2 Gem for AWS Lambda
Home Page: https://lamby.custominktech.com
License: MIT License
Precompiled Mysql2 Gem for AWS Lambda
Home Page: https://lamby.custominktech.com
License: MIT License
I am trying to use a PlanetScale database with my Ruby Lambda, and while I can run it locally and in docker, I get "SSL connection error: unknown error number" when running in Lambda.
require 'active_record'
require 'mysql2-lambda'
require 'mysql2'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: 'xxx',
username: 'xxx',
host: 'xxx',
password: 'xxx,
sslverify: true,
# ssl_mode: :verify_identity,
# sslca: '/etc/ssl/cert.pem',
)
"errorMessage": "SSL connection error: unknown error number",
"errorType": "Function<ActiveRecord::ConnectionNotEstablished>",
"stackTrace": [
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:45:in `rescue in new_client'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:39:in `new_client'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `mysql2_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_handling.rb:327:in `retrieve_connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_handling.rb:283:in `connection'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:553:in `load_schema!'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/attributes.rb:250:in `load_schema!'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:539:in `block in load_schema'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:536:in `synchronize'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:536:in `load_schema'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/model_schema.rb:392:in `columns_hash'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/query_methods.rb:1313:in `arel_column'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:280:in `aggregate_column'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:299:in `execute_simple_calculation'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:269:in `perform_calculation'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:144:in `calculate'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/relation/calculations.rb:51:in `count'",
"/var/task/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/querying.rb:22:in `count'",
"/var/task/router.rb:8:in `router'"
]
The gem doesn't seem to work on ruby 2.7.5
Bundle installs all the gems, but when I try to require the gem, I get this error:
irb(main):002:0> require 'mysql2'
Traceback (most recent call last):
10: from /var/lang/bin/irb:23:in `<main>'
9: from /var/lang/bin/irb:23:in `load'
8: from /var/lang/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
7: from (irb):2
6: from /var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:149:in `require'
5: from /var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:160:in `rescue in require'
4: from /var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:160:in `require'
3: from /var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2.rb:36:in `<top (required)>'
2: from /var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
1: from /var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
LoadError (/var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2/mysql2.so: cannot open shared object file: No such file or directory - /var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2/mysql2.so)
It worked with ruby 2.7.4, but AWS updated the base image with ruby 2.7.5
Here is my Dockerfile:
FROM public.ecr.aws/lambda/ruby:2.7
# Copy dependency management file
COPY lambda/Gemfile ${LAMBDA_TASK_ROOT}
# Install dependencies under LAMBDA_TASK_ROOT
ENV GEM_HOME=${LAMBDA_TASK_ROOT}/vendor/bundle
RUN bundle install
# Copy function code
COPY lambda ${LAMBDA_TASK_ROOT}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "lambda_function.LambdaFunction::Handler.process" ]
The file is there
sh-4.2# ls -l /var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2/mysql2.so
-rwxr-xr-x 1 root root 5363112 Dec 1 15:08 /var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2/mysql2.so
but it doesn't seem to be a dynamic exec
sh-4.2# ldd /var/task/vendor/bundle/gems/mysql2-lambda-0.5.3.1/lib/mysql2/mysql2.so
not a dynamic executable
If https://downloads.mysql.com/archives/
goes away, the curl
in the Dockerfile
will fail, presenting a rather critical external dependency. Is this at all a concern?
I am trying to use it with serverless-ruby-layer, ruby 7.2
getting following error
Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? Could not find 'mysql2' (~> 0.5) among 379 total gem(s)\nChecked in 'GEM_PATH=/opt/ruby/2.7.0:/var/runtime' , execute `gem env` for more information"
Receiving the following error in my files when executing or running tests:
cannot load such file -- mysql2/mysql2
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.