我正在使用 refile 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
正确返回密钥。有任何想法吗?