0

S3 credentials are configured correctly for Paperclip:

# production.rb (same in development.rb)
config.paperclip_defaults = {
  :storage => :s3,
  :path => 'photos/:id/:style/:filename',
  :s3_credentials => {
    :bucket => ENV['aws_bucket'],
    :access_key_id => ENV['aws_access_key'],
    :secret_access_key => ENV['aws_secret_key']
  }
 }

I do see the environment variables set in the Heroku UI, and I can upload photos just fine.

However when I try to destroy the given model on production, I get this error in the log:

2016-01-14T15:48:48.079923+00:00 app[web.1]: Completed 500 Internal Server Error in 591ms (ActiveRecord: 60.3ms)
2016-01-14T15:48:48.082519+00:00 app[web.1]:
2016-01-14T15:48:48.082522+00:00 app[web.1]: AWS::Errors::MissingCredentialsError (
2016-01-14T15:48:48.082523+00:00 app[web.1]: Missing Credentials.
2016-01-14T15:48:48.082524+00:00 app[web.1]:
2016-01-14T15:48:48.082525+00:00 app[web.1]: Unable to find AWS credentials.  You can configure your AWS credentials
2016-01-14T15:48:48.082526+00:00 app[web.1]: a few different ways:
2016-01-14T15:48:48.082526+00:00 app[web.1]:
2016-01-14T15:48:48.082527+00:00 app[web.1]: * Call AWS.config with :access_key_id and :secret_access_key
2016-01-14T15:48:48.082528+00:00 app[web.1]:
2016-01-14T15:48:48.082529+00:00 app[web.1]: * Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
2016-01-14T15:48:48.082529+00:00 app[web.1]:
2016-01-14T15:48:48.082530+00:00 app[web.1]: * On EC2 you can run instances with an IAM instance profile and credentials
2016-01-14T15:48:48.082531+00:00 app[web.1]:   will be auto loaded from the instance metadata service on those
2016-01-14T15:48:48.082531+00:00 app[web.1]:   instances.
2016-01-14T15:48:48.082532+00:00 app[web.1]:
2016-01-14T15:48:48.082533+00:00 app[web.1]: * Call AWS.config with :credential_provider.  A credential provider should
2016-01-14T15:48:48.082533+00:00 app[web.1]:   either include AWS::Core::CredentialProviders::Provider or respond to
2016-01-14T15:48:48.082534+00:00 app[web.1]:   the same public methods.

This all works just fine locally too (obviously using a different S3 bucket). What's the issue? Why am I getting AWS::Errors::MissingCredentialsError just on production even though uploads work fine?

tirdadc
  • 4,603
  • 3
  • 38
  • 45

1 Answers1

1

You probably want to make sure you're on the aws-sdk gem v1 and not aws-sdk v2. Logs make it look like you're on v1 ("AWS::") -- if you're on aws-sdk v2, paperclip won't work. Don't think thoughtbot is going to support it going forward, I recommend you look into direct upload to s3 using jquery-file-uploader (https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails#pre-signed-post) -- Note that article does not show aws-sdk-v2 instructions. The answer linked below does use aws-sdk-v2:

Rails direct to S3 upload using aws-sdk gem and jQuery-File-Upload on heroku

Community
  • 1
  • 1
harrisjb
  • 461
  • 3
  • 7
  • You're right, I was using AWS SDK v2 and according to [this thread](https://github.com/thoughtbot/paperclip/issues/2021), Paperclip support for it won't be available until 5.0.0. Thanks! – tirdadc Jan 18 '16 at 20:14