2017-06-30 59 views
0

我正在使用AWS Lambda運行一個簡單的紅寶石腳本,其github project具有適合我需求的框架。AWS Lambda:無法加載'active_record/connection_adapters/postgresql_adapter'

由於作爲堆棧一部分的Traveling Ruby的限制,在面對幾個ruby和bundler版本衝突之後。

我能夠在本地成功,但後來當我打包和我測試更新的lambda函數,我得到了AWS控制檯上的一個奇怪的錯誤運行腳本:

START RequestId: feab102b-5da5-11e7-bf18-739c73eb4ef0 Version: $LATEST 
2017-06-30T15:08:39.144Z feab102b-5da5-11e7-bf18-739c73eb4ef0 Starting process: ./app 
2017-06-30T15:08:51.403Z feab102b-5da5-11e7-bf18-739c73eb4ef0 stderr: 
/var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
2017-06-30T15:08:51.403Z feab102b-5da5-11e7-bf18-739c73eb4ef0 stderr: 
: Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError) 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/pg-0.21.0/lib/pg.rb:4:in `<top (required)>' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:17:in `<top (required)>' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord 4.2.9/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord 4.2.9/lib/active_record/connection_handling.rb:50:in `establish_connection' 
from /var/task/lib/app/app.rb:12:in `<main>' 

2017-06-30T15:08:51.744Z feab102b-5da5-11e7-bf18-739c73eb4ef0 {"errorMessage":"Process \"./app\" exited with code: 1"} 
END RequestId: feab102b-5da5-11e7-bf18-739c73eb4ef0 

db/config.yml(它調用config/database.yml,因爲它應該默認爲rails樹)我已經設置了adapter: postgresql和所有其他必需的設置。

的代碼完全存儲在.zip文件,我已經解開了,就能夠找到我的猜測拉姆達環境中的/var/task被提取,因爲它顯示在日誌中的lib/vendor/ruby/2.1.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb

我能想到的唯一的事情是,在require那一刻,它在基礎路徑上迷路了,因此沒有找到要加載的文件。

我會很感激任何我可能會失蹤的任何見解或解決此問題的任何線索。

謝謝!

回答

0

它結束了,上面的錯誤是誤導,因爲實際上activerecord搶救異常,並提出了一個自定義錯誤消息,因此不反映現實情況發生在其他地方的棧,而加載pg寶石。實際錯誤是這樣的:

START RequestId: a9e88496-6005-11e7-924c-e7c37f2df3e0 Version: $LATEST 
2017-07-03T15:38:30.977Z a9e88496-6005-11e7-924c-e7c37f2df3e0 Starting process: ./app 
2017-07-03T15:38:42.337Z a9e88496-6005-11e7-924c-e7c37f2df3e0 stderr: 
/var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
2017-07-03T15:38:42.456Z a9e88496-6005-11e7-924c-e7c37f2df3e0 stderr: 
: libpq.so.5: cannot open shared object file: No such file or directory - /var/task/lib/vendor/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/pg-0.21.0/pg_ext.so - libpq.so.5: cannot open shared object file: No such file or directory - /var/task/lib/vendor/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/pg-0.21.0/pg_ext.so - Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile. (LoadError) 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/pg-0.21.0/lib/pg.rb:4:in `<top (required)>' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/postgresql_adapter.rb:17:in `<top (required)>' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `block in require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:240:in `load_dependency' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:274:in `require' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord-4.2.9/lib/active_record/connection_adapters/connection_specification.rb:175:in `spec' 
from /var/task/lib/vendor/ruby/2.1.0/gems/activerecord-4.2.9/lib/active_record/connection_handling.rb:50:in `establish_connection' 
from /var/task/lib/app/app.rb:12:in `<main>' 

2017-07-03T15:38:42.676Z a9e88496-6005-11e7-924c-e7c37f2df3e0 {"errorMessage":"Process \"./app\" exited with code: 1"} 
END RequestId: a9e88496-6005-11e7-924c-e7c37f2df3e0 

真正的原因也隱藏在這個錯誤背後。這並不是因爲在這條路上發現了pg_ext.so

經過一番研究,最後一個問題是,libpg.so.5本身是一個缺少的,並修復,我不得不在Traveling Ruby的庫路徑中添加它。

希望能在未來對他人有所幫助!