我正在为新应用设置有效存储空间,并且在设置我的亚马逊凭据后无法让应用在生产中运行。
credentials.yaml.enc
文件RAILS_MASTER_KEY
env变量添加到Heroku。config.active_storage.service = :amazon
行添加到我的production.rb。config.require_master_key = true
添加到我的production.rb 当我尝试在Heroku上运行我的应用程序时,它无法加载。做$ Heroku运行rails控制台给我错误:
"/app/vendor/bundle/ruby/2.3.0/gems/aws-sigv4-1.0.2/lib/aws-sigv4/signer.rb:517:in `extract_credentials_provider': Cannot load `Rails.config.active_storage.service`: (Aws::Sigv4::Errors::MissingCredentialsError)
missing credentials, provide credentials with one of the following options:
- :access_key_id and :secret_access_key
- :credentials
- :credentials_provider"
据我所知,我已经按照Rails 5.2的方式设置了我的凭据。我尝试过各种各样的资产预编译无济于事。当我尝试将我的亚马逊证书添加为环境时。 Heroku中的变量,应用程序在生产中运行良好。知道这里可能出现什么问题吗?
答案 0 :(得分:3)
是否忘记将config.require_master_key = true
添加到production.rb
?
答案 1 :(得分:2)
仔细检查config/credentials.yml.enc
文件中是否有正确的密钥。我有一个键倒置secret_key_access
而不是secret_access_key
,并且得到了相同的错误。修复了config/credentials.yml.enc
中的密钥名称,为我修复了它。
在rails控制台(本地)中,运行:
Rails.application.credentials.dig(:aws, :access_key_id)
和
Rails.application.credentials.dig(:aws, :secret_access_key)
确保他们有价值观。
答案 2 :(得分:1)
之前我遇到过这个问题,似乎是Heroku上的一个bug。
您只需在设置选项卡上通过Heroku上的仪表板设置环境变量。
然后你可以使用ENV ['NAME_OF_YOUR_VARIABLE']
来访问它这解决了我的问题。
同时检查您的Heroku日志,向上滚动以确保安装了所有宝石。
答案 3 :(得分:0)
亲爱的,这太蠢了。谜团已揭开。我的凭据在credentials.yaml.enc
文件中被注释掉-我使用默认的aws示例将它们添加到了文件顶部。