简体   繁体   English

Aws-sdk gem'无法在远程服务器上加载此类文件'错误,但不能在本地加载

[英]Aws-sdk gem 'cannot load such file' error on remote server but not locally

This looks very similar to other questions but those solutions don't look like they apply here. 这看起来与其他 问题非常相似,但这些解决方案似乎不适用于此处。

I can run my rails app in production mode locally, but on a remote server it fails with a message about the aws-sdk gem: 我可以在本地生产模式下运行我的rails应用程序,但在远程服务器上它失败并显示有关aws-sdk gem的消息:

A LoadError occurred in images#index:

cannot load such file -- aws-sdk (You may need to install the aws-sdk gem)
app/controllers/images_controller.rb:9:in `block (2 levels) in index'

aws-sdk is being used by Paperclip 4.2.0 , which as of now only integrates with aws-sdk 1.x (no version 2). aws-sdk Paperclip 4.2.0正在使用aws-sdk ,它现在只与aws-sdk 1.x集成(没有版本2)。 require 'aws-sdk' is not anywhere in my own code. require 'aws-sdk'不在我自己的代码中。 Offending action code: 违规行为代码:

@images = @viewable.images
respond_to do |format|
  format.html {}
  #line 9:
  format.json {render json: @images, root: false, each_serializer: ImageSerializer}
end

What I've investigated so far follows. 到目前为止我调查的内容如下。

Remote vs Local configuration 远程与本地配置

This seems most likely to be the cause. 这似乎最有可能是原因。 Perhaps some crucial config is not being found by my server such that aws-sdk can't be initialised. 也许我的服务器找不到一些关键的配置,因此aws-sdk无法初始化。 Here's how my config works: 这是我的配置如何工作:

S3 is configured according to this page . 根据该页面配置S3。 I followed the tutorial exactly except for a slight change to accommodate multiple production mode servers: 我完全按照教程,除了稍微更改以适应多个生产模式服务器:

config/application.yml (values loaded to ENV by figaro ): config / application.yml(由figaro加载到ENV ):

production:
  s3_bucket: 'mybucket'

development:
  s3_bucket: 'mybucket'

config/aws.yml (loaded automatically by aws-sdk): config / aws.yml(由aws-sdk自动加载):

development:
  access_key_id: AK_MY_ID
  secret_access_key: MYSECRET
production:
  access_key_id: AK_MY_ID
  secret_access_key: MYSECRET

Excerpt from config/environments/production.rb: 摘自config / environments / production.rb:

config.paperclip_defaults = {
  storage: :s3,
  s3_credentials: {
    bucket: ENV['s3_bucket']
  }
}

As far as I can tell symlinks for each yml file are being created correctly on each deploy: 据我所知,每个部署正确创建每个yml文件的符号链接:

deployer:~/apps/myapp/releases/20150505130826$ ll config/
lrwxrwxrwx  1 deployer deployer    53 May  5 13:08 application.yml -> /home/deployer/apps/myapp/shared/config/application.yml
lrwxrwxrwx  1 deployer deployer    45 May  5 13:08 aws.yml -> /home/deployer/apps/myapp/shared/config/aws.yml

Other things I've checked: 我检查过的其他事情:

I doubt this controller is at fault 我怀疑这个控制器有问题

Other actions and controllers that access the same model also fail, and it fails on the remote server only. 访问同一模型的其他操作和控制器也会失败,并且仅在远程服务器上失败。

Gem installation looks good 宝石安装看起来不错

I have had no problems with other gems being lost during deployment over several months. 在几个月的部署期间,我没有遇到其他宝石丢失的问题。 There is no output from bundler saying that the install has failed. Bundler没有输出说安装失败。 From capistrano deploy output: 来自capistrano部署输出:

 ~/.rvm/bin/rvm ruby-2.1.5@myapp do bundle install --path /home/deployer/apps/myapp/shared/bundle --without development test --deployment --quiet as deployer@myapp.com
DEBUG [c43674b8] Command: cd /home/deployer/apps/myapp/releases/20150505130826 && ~/.rvm/bin/rvm ruby-2.1.5@myapp do bundle install --path /home/deployer/apps/myapp/shared/bundle --without development test --deployment --quiet
INFO [c43674b8] Finished in 3.582 seconds with exit status 0 (successful).

From a shell I can inspect where the gem is installed: 从shell我可以检查gem的安装位置:

~/apps/myapp/releases/20150505130826$ ~/.rvm/bin/rvm ruby-2.1.5@myapp do bundle show aws-sdk
/home/deployer/apps/myapp/shared/bundle/ruby/2.1.0/gems/aws-sdk-1.64.0

In the rails console: 在rails控制台中:

2.1.5 :001 > Gem.loaded_specs['aws-sdk'].full_gem_path
 => "/home/deployer/apps/myapp/shared/bundle/ruby/2.1.0/gems/aws-sdk-1.64.0"

So it seems like Rails does know about the gem. 所以看起来Rails 确实知道宝石。

AWS credentials look good AWS凭证看起来不错

Identical credentials work perfectly (in dev mode and in production mode) on my local machine. 相同的凭证在我的本地计算机上完美地工作(在开发模式和生产模式下)。 Credentials also work using s3cmd on the remote server. 凭据也可以在远程服务器上使用s3cmd。 When I deliberately set them to incorrect values on my local machine, I get Access Denied errors from AWS, not the whole action falling over like this. 当我故意在本地计算机上将它们设置为不正确的值时,我从AWS获得了Access Denied错误,而不是像这样的整个操作。

Where else can I look for problems? 我还能在哪里寻找问题?

I tried using the gem 'aws-sdk-v1' . 我尝试使用gem 'aws-sdk-v1' It was work well for my aws project. 这对我的aws项目很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM