Forum: Ruby Nested Hash AWS API Call

B3249573a5345f4681c66a9430e8b3bc?d=identicon&s=25 Pierre-Andre M. (pierreandre_m)
on 2013-09-13 02:10
I am trying to make a call and retrieve meaningful data via the
"describe_instance" method within the Ruby AWS SDK.  I'm pretty new to
ruby and it seems I'm missing something fundamental about nested
hashes...anyway...

Here is the doc I'm using as reference http://amzn.to/1baKQ2h

Here is how I set things up (I changed all the data):

aws_instance = @ec2.client.describe_instances(:instance_ids =>
['i-gggggg'])
aws_instance.describe_instance

for example, I would like to retrieve the "availability_zone" which
appears to be nested (in the documentation) within the "placement" hash
which is in the "instances" set.

Can someone form a sample call that I could use as a reference?
09a32175057418748822c587ac08c429?d=identicon&s=25 Abinoam Jr. (abinoampraxedes_m)
on 2013-09-13 23:44
(Received via mailing list)
From:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/C...

I can guess ...

response = @ec2.client.describe_instances(:instance_ids => ['i-gggggg'])

instance = response.data[:reservation_set].first[:instance_set].first

availability_zone = instance[:placement][:availability_zone]


Note 1: When it says "Array" it's an Array of Hashes. So, if I call
"first" on it, I have a Hash in return and I can call [] on it.
Note 2: I have no means to test this. Just let me know if it works.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.