生产中未找到AWS凭证

时间:2015-01-30 22:21:04

标签: ruby-on-rails amazon-s3 aws-sdk refile

我使用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

正确返回密钥。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

确保还设置了生产密钥。生产和开发是两种不同的环境。如果你已经部署到像heroku这样的东西,你将不得不手动设置或者在布拉德提到的figaro gem之类的帮助下设置它们。

以下是一些资源

http://www.gotealeaf.com/blog/managing-environment-configuration-variables-in-rails