问题
I am trying to use padrino to build a dashboard for my amazon environment. But when I try the following piece of code in the controller:
get :index, :map => "/" do
AWS.config(access_key_id: 'ACCESS_KEY',
secret_access_key: 'secret_access_key',
region: 'ap-southeast-2')
ec2 = AWS::EC2.new
response = ec2.client.describe_instances(:instance_ids => ['instance_id'])
@instance = response[:reservation_set].first[:instances_set].first
render 'index'
end
I got the following errors:
SocketError - getaddrinfo: nodename nor servname provided, or not known:
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:in initialize'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:inopen'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:in block in connect'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:66:intimeout'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:876:in connect'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:indo_start'
/Users/mymac/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:857:in start'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/http/connection_pool.rb:309:instart_session'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/http/connection_pool.rb:125:in session_for'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/http/net_http_handler.rb:55:inhandle'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:252:in block in make_sync_request'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:288:inretry_server_errors'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:248:in make_sync_request'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:510:inblock (2 levels) in client_request'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:390:in log_client_request'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:476:inblock in client_request'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:372:in return_or_raise'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/aws-sdk-1.37.0/lib/aws/core/client.rb:475:inclient_request'
(eval):3:in describe_instances'
/Users/mymac/dev/padrino_workspace/aem_dashboard/app/controllers/aem.rb:24:inblock (2 levels) in '
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:699:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:699:inblock in route'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:62:in []'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:62:inblock (3 levels) in process_destination_path'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:976:in route_eval'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:62:inblock (2 levels) in process_destination_path'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:62:in catch'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:62:inblock in process_destination_path'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:37:in instance_eval'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:37:inprocess_destination_path'
(eval):20:in block in call'
(eval):9:incatch'
(eval):9:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/http_router-0.11.1/lib/http_router.rb:288:inraw_call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/http_router-0.11.1/lib/http_router.rb:142:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:1101:inroute!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:1086:in block in dispatch!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:inblock in invoke'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in catch'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:ininvoke'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/application/routing.rb:1084:in dispatch!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:inblock in call!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in block in invoke'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:incatch'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1049:in invoke'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:889:incall!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:877:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sass-3.3.3/lib/sass/plugin/rack.rb:54:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/xss_header.rb:18:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/json_csrf.rb:18:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/base.rb:50:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-protection-1.5.2/lib/rack/protection/frame_options.rb:31:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/head.rb:11:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/reloader/rack.rb:22:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/logger.rb:398:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/show_exceptions.rb:21:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:incontext'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:2004:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in block in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1778:insynchronize'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.4/lib/sinatra/base.rb:1469:in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/router.rb:82:inblock in call'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/router.rb:75:in each'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/router.rb:75:incall'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/connection.rb:86:in block in pre_process'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/connection.rb:84:incatch'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/connection.rb:84:in pre_process'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/connection.rb:53:inprocess'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/connection.rb:39:in receive_data'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:inrun_machine'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in run'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/backends/base.rb:73:instart'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.6.2/lib/thin/server.rb:162:in start'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:inrun'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/server.rb:264:in start'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/server.rb:50:instart'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/server.rb:39:in start'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/server.rb:12:inrun!'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/cli/adapter.rb:7:in start'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/lib/padrino-core/cli/base.rb:32:instart'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.17.0/lib/thor/task.rb:27:in run'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.17.0/lib/thor/invocation.rb:120:ininvoke_task'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.17.0/lib/thor.rb:344:in dispatch'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.17.0/lib/thor/base.rb:434:instart'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/gems/padrino-core-0.12.0/bin/padrino:9:in <top (required)>'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/bin/padrino:23:inload'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/bin/padrino:23:in <main>'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:ineval'
/Users/mymac/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `'
Here is my gem file:
ruby '2.0.0'
gem 'rake'
gem 'thin'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'sass'
gem 'haml'
gem 'mongoid', '~>3.0.0'
gem 'mocha', :group => 'test', :require => false
gem 'shoulda', :group => 'test'
gem 'rack-test', :require => 'rack/test', :group => 'test'
gem 'padrino', '0.12.0'
gem "bootstrap-sass", "~> 3.1.1.0"
gem 'aws-sdk', '~> 1.37.0'
gem 'rest-client', '~> 1.6.7'
gem 'net-ping', '~> 1.7.2'
If I try the following code in irb, sinatra and rails, it works well:
AWS.config(access_key_id: 'ACCESS_KEY',
secret_access_key: 'secret_access_key',
region: 'ap-southeast-2')
ec2 = AWS::EC2.new
response = ec2.client.describe_instances(:instance_ids => ['instance_id'])
@instance = response[:reservation_set].first[:instances_set].first
Can anyone please help me out. Thank you.
I am using ruby 2.0.0, padrino 0.12.0 and OS X 10.8.2. Regards Johnny
回答1:
Your region configuration may be wrong. I ran into the same error when trying to access an S3 bucket. Since my bucket was on us-standard, aka 'us-east-1', this configuration ended up working:
AWS.config(access_key_id: 'xxx',
secret_access_key: 'xxx',
region: 'us-west-1',
s3: { region: 'us-east-1' })
来源:https://stackoverflow.com/questions/22588089/socketerror-at-getaddrinfo-nodename-nor-servname-provided-or-not-known-padri