2017-06-30 64 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的库路径中添加它。

希望能在未来对他人有所帮助!