gwalshington
gwalshington

Reputation: 1495

KeyError: key not found: "S3_BUCKET_NAME"

I installed S3, and it works great on heroku. When I try to run RAILS_ENV=production bundle exec rake assets:precompile to push assets to heroku, it return the above error. If I run heroku config, it already has the S3 bucket and everything else set.

What is it looking for, and why can't it find S3 name just to compile assets.

In production.rb

config.paperclip_defaults = {
  storage: :s3,
    s3_credentials: {
      bucket: ENV.fetch('S3_BUCKET_NAME'),
      access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
      secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
      s3_region: 'us-west-2',
    }
 }

I've found a couple SO on this, but none are pointing me towards a solution. Any help is appreciated!

UPDATE: The reason I have to compile locally is because heroku is taking out the application.js file.

remote:        Running: rake assets:precompile
remote:        I, [2016-09-23T15:12:53.753671 #267]  INFO -- : Writing /tmp/build_97a8fe2ca07bc4bf090be26f2be2872b/public/assets/application-9c608f99ae2b1980d74ba674b9f9ff7f0ae113d532e2c2ea580960a6a53346bb.js
remote:        Asset precompilation completed (6.54s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote:        I, [2016-09-23T15:12:55.908630 #273]  INFO -- : Removed application-489c5647af1ca8b6a56e560e8a83d77a1a070778dabb4f0b40f55c4a4e5b8feb.js

Upvotes: 1

Views: 1417

Answers (1)

user229044
user229044

Reputation: 239230

You're trying to compile assets locally, where the S3_BUCKET_NAME config property on Heroku has no effect.

If you want to run your app locally (this includes running Rake tasks), you need to define that environment variable.

That said, this statement makes no sense:

When I try to run RAILS_ENV=production bundle exec rake assets:precompile to push assets to heroku,

There is no reason to you need to run rake assets:precompile locally to "push assets" to Heroku. Heroku will automatically compile your assets for you each time you push new commits to it.

Upvotes: 1

Related Questions