Open akawalsky opened 3 years ago
I don't use PG with Lambda so I have no experience to help, but maybe try looking through the Lamby docs (https://lamby.custominktech.com/docs/database_options) or forums for some tips?
I don't use PG, or Rails, with Lambda either. I don't think Rails is a great fit for Lambda, but if you want to go down that route, I would suggest using a container image https://docs.aws.amazon.com/lambda/latest/dg/images-create.html.
I think that will be a much better experience than trying to use the Serverless framework and this plugin.
I had success with serverless-ruby-layer plugin. Check it out https://navarasu.github.io/serverless-ruby-layer/#/use_docker_with_yums
You might also take a look at https://github.com/boltops-tools/jets for a rails-like serverless framework.
I am trying to create a lambda that works with a rails project. This involve using the
pg
gem and theactive_record
gem.Gemfile
In order to use the
pg
gem, I had to extend the base lambci/lambda:build-ruby2.7 image in order for extensions to be installed correctly. Some of the packages installed are probably unnecessary, but shouldn't make a difference.Dockerfile
The extension files were not being picked up by my lambda, so I manually included them in
lib
borrowing from this script https://github.com/proton/lambda-ruby-pg/blob/main/deploy.bash .I then include those files in my
serverless.yml
Finally, I create the ActiveRecord connection with
handlers.rb
Everything works expect the establish_connection call. I am getting
This error is being caused by this line https://github.com/rails/rails/blob/3de9669188b543192571932e5cb6f0d5a6ec1043/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L4
I confirmed this by manually commenting out that line in my /vendor/bundle before deploying and everything worked. I also have tried commenting out the
establish_connection
call and just callingPG.library_version
, which works. I also tried just puttinggem "pg", ">= 0.18", "< 2.0"
directly in my code and got the same error result.It seems like the
GEM_PATH
being used by this command does not use the sameLOAD_PATHS
variable that is populated by bundler in standalone mode.I don't think this is necessarily a bug with this plugin, but any guidance would be greatly appreciated.