Ruby AWS 开发工具包错误.值 nil 在 module_inheritable_attributes.rb 中



我有以下脚本:

require 'httparty'
require 'aws-sdk-s3'
include HTTParty
Aws.config.update({
region: 'us-east-1',
credentials: Aws::Credentials.new('...', '...')
})
client = Aws::S3::Resource.new
movies = self.class.get("#{HOST}/movies")

当我运行它时,我遇到了以下错误:

Traceback (most recent call last):
10: from script.rb:33:in `<main>'
9: from script.rb:33:in `new'
8: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-athena-1.22.0/lib/aws-sdk-athena/resource.rb:14:in `initialize'
7: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/base.rb:99:in `new'
6: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-athena-1.22.0/lib/aws-sdk-athena/client.rb:262:in `initialize'
5: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/base.rb:19:in `initialize'
4: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/base.rb:62:in `build_config'
3: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/configuration.rb:149:in `build!'
2: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/configuration.rb:158:in `empty_struct'
1: from /Users/me/.rvm/gems/ruby-2.6.5/gems/aws-sdk-core-3.78.0/lib/seahorse/client/configuration.rb:158:in `new'
/Users/me/.rvm/gems/ruby-2.6.5/gems/httparty-0.17.1/lib/httparty/module_inheritable_attributes.rb:42:in `inherited': undefined method `each' for nil:NilClass (NoMethodError)

浏览了AWS的文档和教程后,我仍然找不到问题所在。可能出了什么问题?

我发现问题是行include HTTParty.我在那行之前声明了 S3 客户端,它现在可以工作了:

require 'httparty'
require 'aws-sdk-s3'
Aws.config.update({
region: 'us-east-1',
credentials: Aws::Credentials.new('...', '...')
})
client = Aws::S3::Resource.new
include HTTParty
movies = self.class.get("#{HOST}/movies")

最新更新