Cannot load Rails.config.active_storage.service

Simon Cooper picture Simon Cooper · Jul 6, 2018 · Viewed 13.4k times · Source

I'm setting up a new rails 5.2 app utilising Active Storage and using AWS for the hosting of images in production.

However, I'm having an issue with the app reading the credentials:

2018-07-06T08:11:52.625415+00:00 app[web.1]: ! Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: Cannot load `Rails.config.active_storage.service`:
2018-07-06T08:11:52.625432+00:00 app[web.1]: missing credentials, provide credentials with one of the following options:
2018-07-06T08:11:52.625435+00:00 app[web.1]:   - :access_key_id and :secret_access_key
2018-07-06T08:11:52.625437+00:00 app[web.1]:   - :credentials
2018-07-06T08:11:52.625479+00:00 app[web.1]:   - :credentials_provider

This is an existing S3 Bucket which I created a new user just for this app. I'm happy with the CORS etc.

The user is set up under the S3FullAccess group.

I've edited the credentials in my app via $EDITOR="atom --wait" rails credentials:edit

The contents of the file:

aws:
  access_key_id: [my access key]
  secret_access_key: [my secrect key]

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: [my secret key base]

Appreciate this is in YAML format, I have played with using one space, and one tab on the keys, but this doesn't seem to make a difference.

When I save and close the file, the terminal writes New credentials encrypted and saved.

I also have gem 'aws-sdk-s3', '~>1', require: false installed.

And config/storage.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: eu-west-2
  bucket: [mybucket]

Any suggestions on what I might be doing wrong?

Answer

Jhonathan A picture Jhonathan A · Jul 19, 2018

I think you're missing the master.key file in your server. Check your local repo in config/master.key (this file is added to your .gitignore by default). Add this file to your server or set ENV["RAILS_MASTER_KEY"].