Key is there but I still get `fetch': key not found: “S3_BUCKET_NAME” (KeyError)

允我心安 提交于 2019-12-24 09:04:02

问题


I know there's a ton of these asked, but I've tried to follow each one with no luck. There must be some easy mistake that I am overlooking.

I'm trying to set up S3 and Paperclip following the Heroku guide and set up local testing following this Words and Code guide. Every time I try to generate a db migration though I get the error:

config/environments/development.rb:62:in fetch': key not found: "S3_BUCKET_NAME" (KeyError)

These are my files exactly with keys replaced:

development.rb

config.paperlip_defaults = {
    storage: :s3,
    s3_credientials: {
      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: ENV.fetch('AWS_REGION')
    }
  }

.ENV

S3_BUCKET_NAME=some-bucket-name
AWS_ACCESS_KEY_ID=AAAAAABBBBBCCCCCDDDD
AWS_SECRET_ACCESS_KEY=AAAAABBBBBCCCCCDDDDDEEEEE
AWS_REGION=us-east-1

What am I missing?

Edit: I have tried adding the ENV values to my ~/.bashrc and ~/.bash_profle as suggested in this question, with the same error.


回答1:


The answer turned out to be pretty easy with a gem.

I added dotenv-rails to my gemfile

group :development, :test do
  gem 'dotenv-rails'
end

bundle install and good to go.

I guess I never realized that the .env file saved in the root directory wasn't loaded automatically.



来源:https://stackoverflow.com/questions/42979019/key-is-there-but-i-still-get-fetch-key-not-found-s3-bucket-name-keyerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!