flexera-public / right_aws

RightScale Amazon Web Services Ruby Gems
MIT License
451 stars 175 forks source link

RightAws::Ec2.new() return an empty array #178

Closed giamma13 closed 4 years ago

giamma13 commented 10 years ago

I am trying to use right_aws to get the list of instances running in my account.

I am providing the correct combination for MY_KEY/MY_SECRET_KEY but I do not get anything back.

And I do have 1 instance running in the region "eu-west-1"

Any idea ?

Here is the output from the Rails console. As you can see I am on Ruby 2 (Rails 4)

2.0.0p247 :019 > aws = RightAws::Ec2.new("MY_KEY", "MY_SECRET_KEY", :region=>"eu-west-1") New RightAws::Ec2 using shared connections mode => #<RightAws::Ec2:0xe5f6cd0 @params={:region=>"eu-west-1", :server=>"eu-west-1.ec2.amazonaws.com", :port=>443, :service=>"/", :protocol=>"https", :host_to_sign=>"eu-west-1.ec2.amazonaws.com", :connection_options=>{}, :connections=>:shared, :max_connections=>10, :connection_lifetime=>1200, :api_version=>"2011-02-28"}, @aws_access_key_id="MY_KEY", @aws_secret_access_key="MY_SECRET_KEY", @with_connection_options={}, @logger=#<ActiveSupport::Logger:0xd3ba4b8 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0xd3ba454 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0xd8711b4 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0xd3ba404 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<File:/media/sf_BEWE/GitHub_Linux/React/log/development.log>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0xd3ba3f0 @mon_owner=nil, @mon_count=0, @mon_mutex=#>>>, @error_handler=nil, @cache={}, @signature_version="2">

2.0.0p247 :020 > aws.describe_instances => []

safiire commented 10 years ago

If you are using Ruby >= version 2.0, this is because Net::HTTP is returning a gzipped HTTP body for your API request (because it does not automatically unzip it now??), and right_aws is getting this compressed body for a response.

The right_aws gem, instead of throwing an exception because it cannot parse the compressed response like it should, is simply returning [] which is an incorrect response to not understanding the http body, so this is a bug.

safiire commented 10 years ago

I have seen monkey patches which change the behavior of Net::HTTP so that it will unzip a gzipped response, and I am contemplating using it. That would fix this problem, but I a a little concerned that right_aws will not complain if it can't understand a response body, and it just returns [].

konstantin-dzreev commented 10 years ago

Plz try https://github.com/rightscale/right_aws_api

It is not compatible with right_aws in inputs/outputs but it is much more flexible. And it does not monkey patch net/http, so gzip works fine there