我正在尝试从我的heroku rails应用程序运行此导入任务,该应用程序连接到AWS并抓取CSV但得到以下错误(完整错误如下所示):
ArgumentError:参数数量错误(给定1,预期2..3)
非常感谢任何帮助。
以下是我的initializers / aws.rb文件中的代码,其中我提供了凭据:
Aws.config.update({
region: 'us-east-2',
credentials: Aws::Credentials.new(access_key_id:
ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
})
这是任务(在我的一个rake文件中):
desc "import for CSV to S3"
task import: [:environment] do
s3 = Aws::S3::Client.new(region:'us-east-2', credentials: credentials)
File.open('nba_data.csv', 'wb') do |file|
reap = s3.get_object({ bucket: 'nba-api', key: 'nba_data.csv'}, target: file)
csv_text = File.read('nba_data.csv')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
Player.create!(row.to_hash.except("id"))
end
end
end
这是完整的控制台错误
Franks-MacBook-Air:nba_site frankburke $ heroku run rails player_query:import
运行rails player_query:导入⬢protected-tundra-94123 ...... up,run.3454(免费)
铁轨中止了!
ArgumentError:参数个数错误(给定1,预期2..3)
/app/vendor/bundle/ruby/2.3.0/gems/aws-sdk-core-3.19.0/lib/aws-sdk-core/credentials.rb:7:in initialize'
/app/config/initializers/aws.rb:4:in
new'
/app/config/initializers/aws.rb:4:in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in
loading&#39;
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in block in load'
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in
load_dependency&#39;
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in load'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:648:in
阻止在load_config_initializer&#39;
在/ {/ 1}} load_config_initializer&#39;
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:612:in instrument'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:647:in
每个&#39;
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:611:in block (2 levels) in <class:Engine>'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/engine.rb:611:in
instance_exec&#39;
run_initializers&#39;中的/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in block in <class:Engine>'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:30:in
阻止
在/ {/ 1}} tsort_each_child&#39;
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:54:in run'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:55:in
初始化!&#39;
/app/config/environment.rb:5:in each'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/initializable.rb:44:in
要求&#39;
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:328:in run_initializers'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:352:in
阻止在run_tasks_blocks&#39;
在/ {/ 1}} run_rake_task&#39;
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:51:in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:328:in
&#39;
/ app / bin / rails:9:require_environment!'
/app/vendor/bundle/ruby/2.3.0/gems/railties-5.0.2/lib/rails/application.rb:448:in
&#39;
任务:TOP =&gt; player_query:import =&gt;环境
(通过使用--trace运行任务查看完整跟踪)
答案 0 :(得分:1)
Aws.config.update({
region: 'us-east-2',
credentials: Aws::Credentials.new(access_key_id:
ENV['AWS_ACCESS_KEY_ID'], secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
})
到这个
Aws.config.update({
region: 'us-east-2',
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
})