Aws-sdk gem "cannot download such file" on remote server but not locally
This is similar to other questions , but these solutions are not similar to their application. here.
I can run the rails app in production mode locally, but on the remote server it fails with the aws-sdk
gem message :
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
used Paperclip 4.2.0
which now only integrates with aws-sdk 1.x (no version 2). require 'aws-sdk'
missing in my own code. Action code violation:
@images = @viewable.images
respond_to do |format|
format.html {}
#line 9:
format.json {render json: @images, root: false, each_serializer: ImageSerializer}
end
What I have researched so far follows.
Remote and local configuration
This will most likely be the reason. Perhaps some critical config was not found on my server, so aws-sdk cannot be initialized. This is how my config works:
S3 is configured according to this page . I followed the tutorial closely, except for a small change to host multiple production mode servers:
config / application.yml (values loaded in ENV
figaro ):
production:
s3_bucket: 'mybucket'
development:
s3_bucket: 'mybucket'
config / aws.yml (automatically loaded by 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 / environment / production.rb:
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: ENV['s3_bucket']
}
}
As far as I can tell, the symlinks for each yml file are created correctly on every deployment:
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 faulty
Other actions and controllers that access the same model also fail, and they only fail on the remote server.
Gem setup looks good
I had no problem losing other gems during deployment for several months. The provider has no exit indicating that the installation has failed. From capistrano deployment output:
~/.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 the shell, I can check where the stone is installed:
~/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:
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 looks like Rails knows about the stone.
AWS credentials look good
Identical credentials work fine (in dev mode and production mode) on my local machine. The credentials are also working using s3cmd on the remote server. When I deliberately set them to wrong values on my local machine, I get Access Denied errors from AWS, not all activities falling this way.
Where else can you look for problems?
source to share