缺少必需的参数:aws_access_key_id,aws_secret_access_key

时间:2015-03-11 19:01:57

标签: ruby-on-rails rspec carrierwave

我目前正在尝试在终端中运行我的测试套件但是我收到以下错误:

Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)

我在我的项目中使用Carrierwave,我很确定这是导致问题的原因。这是我的config / initializers / carrierwave.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                       
    :aws_access_key_id      => ENV['S3_ACCESS_KEY_ID'],                        
    :aws_secret_access_key  => ENV['S3_SECRET_ACCESS_KEY']
  }
  config.fog_directory  = 'my_directory'                    

end

这是我的日志:

News-MacBook-Pro:music-app yedidyaweiner$ bundle exec rspec
/Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/fog-core-1.27.2/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/fog-core-1.27.2/lib/fog/core/service.rb:268:in `handle_settings'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/fog-core-1.27.2/lib/fog/core/service.rb:98:in `new'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/fog-core-1.27.2/lib/fog/storage.rb:25:in `new'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
    from /Users/yedidyaweiner/projects/music-app/config/initializers/carrierwave.rb:2:in `block in <top (required)>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
    from /Users/yedidyaweiner/projects/music-app/config/initializers/carrierwave.rb:1:in `<top (required)>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/engine.rb:648:in `block in load_config_initializer'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/activesupport-4.1.1/lib/active_support/notifications.rb:161:in `instrument'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/engine.rb:647:in `load_config_initializer'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/engine.rb:611:in `each'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/engine.rb:611:in `block in <class:Engine>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:44:in `each'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `call'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /Users/yedidyaweiner/.rbenv/versions/2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
    from /Users/yedidyaweiner/projects/music-app/config/environment.rb:5:in `<top (required)>'
    from /Users/yedidyaweiner/projects/music-app/spec/rails_helper.rb:4:in `require'
    from /Users/yedidyaweiner/projects/music-app/spec/rails_helper.rb:4:in `<top (required)>'
    from /Users/yedidyaweiner/projects/music-app/spec/controllers/comments_controller_spec.rb:1:in `require'
    from /Users/yedidyaweiner/projects/music-app/spec/controllers/comments_controller_spec.rb:1:in `<top (required)>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/bin/rspec:23:in `load'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/bin/rspec:23:in `<main>'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/yedidyaweiner/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'

我需要做些什么才能摆脱这个错误并运行我的测试?

3 个答案:

答案 0 :(得分:11)

您需要设置环境变量S3_ACCESS_KEY_IDS3_SECRET_ACCESS_KEY,以便它们在Rails中可用。您可以在终端中执行此操作:

export S3_ACCESS_KEY_ID=<your access key id>
export S3_SECRET_ACCESS_KEY=<your secret access key>

将它们添加到.bashrc或.bash_profile中,以便它们在您下次启动新shell时使用,或使用dotenv之类的内容使其专用于您的项目。

答案 1 :(得分:1)

除了明显的解决方案之外,设置正确的ENV VARS,另外一个问题,我遇到的是 spring 。我正确设置了ENV vars,但是它们只是不被carrierwave.rb初始化程序识别。由于spring用于预加载应用程序以及 rake rspec 等过程,因此没有考虑新创建的ENV VARS。重新启动弹簧固定了那个。

答案 2 :(得分:0)

如果您使用figaro gem来管理您的AWS密码,您可以尝试:
  - figaro heroku:set -e production
  - 然后写heroku config,你将检查当前的配置 如果一切正常,将列出您的AWS_ACCESS_KEY等。