我正在使用重新归档 gem 将 rails 应用程序部署到生产环境以进行文件上传并连接到 s3 进行存储。在开发中一切正常 尝试上传新图像或检索现有图像时,我在生产中遇到以下错误:
E, [2015-01-30T16:59:02.841941 #29551] ERROR -- : Refile::App: Error ->
Missing Credentials.
Unable to find AWS credentials. You can configure your AWS credentials
a few different ways:
* Call AWS.config with :access_key_id and :secret_access_key
* Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
* On EC2 you can run instances with an IAM instance profile and credentials
will be auto loaded from the instance metadata service on those
instances.
* Call AWS.config with :credential_provider. A credential provider should
either include AWS::Core::CredentialProviders::Provider or respond to
the same public methods.
= Ruby on Rails
In a Ruby on Rails application you may also specify your credentials in
the following ways:
* Via a config initializer script using any of the methods mentioned above
(e.g. RAILS_ROOT/config/initializers/aws-sdk.rb).
* Via a yaml configuration file located at RAILS_ROOT/config/aws.yml.
This file should be formated like the default RAILS_ROOT/config/database.yml
file.
E, [2015-01-30T16:59:02.842423 #29551] ERROR -- : Refile::App: /home/deploy/real_org/shared/bundle/ruby/2.1.0/gems/aws-sdk-v1-1.60.2/lib/aws/core/credential_providers.rb:140:in `credentials'
我已经在 RAILS_ROOT/config/initializers/aws-sdk.rb 文件中配置了凭据,如下所示
require 'aws-sdk'
AWS.config(access_key_id: ENV["AWS_ACCESS_KEY_ID"], secret_access_key: ENV["AWS_SECRET_KEY"])
我已经通过键入确认了 env 变量的存在
$: echo $AWS_SECRET_KEY
$: echo $AWS_ACCESS_KEY_ID
正确返回密钥。有什么想法吗?
确保还设置了生产密钥。生产和开发是两个不同的环境。如果您已部署到类似 heroku 的东西,则必须手动或在 Brad 提到的费加罗宝石之类的东西的帮助下设置它们。
以下是一些资源
http://www.gotealeaf.com/blog/managing-environment-configuration-variables-in-rails