我曾在〜/ .bashrc保存一些ENV
的,請重新打開該文件,我可以有看到他們:然而如何讓我的Rails應用程序使用我的〜/ .bashrc保存的ENV VARS?
export SECRET_KEY_BASE="secretkeyhere"
export S3_SECRET_KEY="anotherhere"
export S3_ACCESS_KEY="andhere"
export DEVISE_KEY="and again"
,當我告訴我的Rails應用程序使用它們,例如S3憑據在我與ENV["S3_ACCESS_KEY"]
模型它似乎沒有使用它們,給我的錯誤:
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.
當殼我運行echo $DEVISE_KEY
並返回不過是一個空行,如果我跑source ~/.bashrc
然後echo $DEVISE_KEY
它返回鍵?!?因此,它似乎在某處,但不能通過rails和/或正確的會話/環境/程序訪問。作爲UNIX的初級,Rails以及更多,我現在對這裏發生的事情感到不知所措。請你能幫我理解我在這裏做錯了什麼。謝謝。
您是否嘗試過採購您的bashrc文件? – Joel 2015-02-09 22:33:15
我試着在bash窗口中運行'source〜/ .bashrc',然後'echo $ DEVISE_KEY'會返回密鑰。然而,Rails仍然在PostsController#create'錯誤中返回相同的'AWS :: Errors :: MissingCredentialsError? – jbk 2015-02-10 11:05:50