GithubHelp home page GithubHelp logo

customink / mysql2-lambda Goto Github PK

View Code? Open in Web Editor NEW
23.0 37.0 6.0 16 KB

Precompiled Mysql2 Gem for AWS Lambda

Home Page: https://lamby.custominktech.com

License: MIT License

Dockerfile 34.29% Shell 33.45% Ruby 32.22% Starlark 0.05%
aws-lambda ruby-on-rails aws fullstack-serverless mysql2 mysql rds rds-proxy

mysql2-lambda's Issues

SSL Support?

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'"
    ]

Ruby 2.7.5

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

external dependency on downloads.mysql.com

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?

Unable to get it working with serverless-ruby-layer

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.