0

I have deployed a Rails 5 app on a Ubuntu 16.04 server. There is however a problem with the Paperclip configuration.

I'm using the Figaro gem to store my environment variables. My paperclip configuration looks like this:

config/environments/production.rb

config.paperclip_defaults = {
  storage: :s3,
  bucket: 'anthonycandaele',
  s3_region: 'eu-west-1',
  s3_credentials: {
    access_key_id: ENV.fetch("AWS_ACCESS_KEY_ID"),
    secret_access_key: ENV.fetch("AWS_SECRET_ACCESS_KEY"),
    s3_host_name: "s3-eu-west-1.amazonaws.com",
  }

}

this worked fine in development.

But when I try to deploy my app, I get a failure when I try to deploy with Capistrano:

log/capistrano.log

INFO [3b1c6af3] Running bundle exec rake assets:precompile as   deploy@146.185.164.246
3245  DEBUG [3b1c6af3] Command: cd   /opt/www/personalsite/releases/20170119174557 && ( export    RAILS_ENV="production" ; bundle exec rake assets:precompile )
3246  DEBUG [3b1c6af3] »·rake aborted!
3247  DEBUG [3b1c6af3] »·KeyError: key not found: "AWS_ACCESS_KEY_ID"

So I tried to fix the problem with adjusting the Paperclip configuration:

config.paperclip_defaults = {
storage: :s3,
bucket: 'anthonycandaele',
s3_region: 'eu-west-1',
s3_credentials: {
  access_key_id: ENV["AWS_ACCESS_KEY_ID"],
  secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
  s3_host_name: "s3-eu-west-1.amazonaws.com",
}

}

now I'm able to deploy with Capistrano, but when I try to upload a file with the app, I'm getting a missingcredentialserror with AWS:

Aws::Errors::MissingCredentialsError (unable to sign request without credentials set):

Has anyone experience with using Paperclip and storing the environment variables with Figaro?

Thanks for your help,

Anthony

Toontje
  • 1,415
  • 4
  • 25
  • 43
  • My guess is that the secrets are not actually set in the environment when you deploy. Could you try adding `puts ENV["AWS_SECRET_ACCESS_KEY"]` to your production.rb to see if anything gets dumped out? – will_in_wi Jan 20 '17 at 05:00
  • you are right, I puts the AWS_SECRET_ACCESS_KEY on the development server and I got the value back. But when I puts the AWS_SECRET_ACCESS_KEY on the production server, I get no value back. How can I solve this? – Toontje Jan 20 '17 at 18:00

1 Answers1

0

I was able to fix the issue by setting a remote config/application.yml file

Toontje
  • 1,415
  • 4
  • 25
  • 43