grempe-amazon-ec2 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/History.txt +230 -0
  2. data/License.txt +66 -0
  3. data/Manifest.txt +46 -0
  4. data/README.txt +154 -0
  5. data/Rakefile +4 -0
  6. data/bin/ec2-gem-example.rb +61 -0
  7. data/bin/ec2sh +73 -0
  8. data/bin/setup.rb +19 -0
  9. data/config/hoe.rb +76 -0
  10. data/config/requirements.rb +17 -0
  11. data/lib/EC2.rb +254 -0
  12. data/lib/EC2/console.rb +44 -0
  13. data/lib/EC2/elastic_ips.rb +153 -0
  14. data/lib/EC2/exceptions.rb +136 -0
  15. data/lib/EC2/image_attributes.rb +166 -0
  16. data/lib/EC2/images.rb +134 -0
  17. data/lib/EC2/instances.rb +206 -0
  18. data/lib/EC2/keypairs.rb +94 -0
  19. data/lib/EC2/products.rb +43 -0
  20. data/lib/EC2/responses.rb +175 -0
  21. data/lib/EC2/security_groups.rb +232 -0
  22. data/lib/EC2/version.rb +18 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/script/txt2html +74 -0
  26. data/setup.rb +1585 -0
  27. data/tasks/deployment.rake +27 -0
  28. data/tasks/environment.rake +7 -0
  29. data/tasks/website.rake +17 -0
  30. data/test/test_EC2.rb +52 -0
  31. data/test/test_EC2_console.rb +54 -0
  32. data/test/test_EC2_elastic_ips.rb +144 -0
  33. data/test/test_EC2_image_attributes.rb +238 -0
  34. data/test/test_EC2_images.rb +197 -0
  35. data/test/test_EC2_instances.rb +325 -0
  36. data/test/test_EC2_keypairs.rb +123 -0
  37. data/test/test_EC2_products.rb +48 -0
  38. data/test/test_EC2_responses.rb +102 -0
  39. data/test/test_EC2_security_groups.rb +205 -0
  40. data/test/test_EC2_version.rb +44 -0
  41. data/test/test_helper.rb +20 -0
  42. data/website/index.txt +427 -0
  43. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  44. data/website/stylesheets/screen.css +138 -0
  45. data/website/template.rhtml +55 -0
  46. metadata +174 -0
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "The EC2 Gem " do
14
+
15
+
16
+ setup do
17
+ @major = 0
18
+ @minor = 2
19
+ @tiny = 10
20
+ @string = [@major, @minor, @tiny].join('.')
21
+ end
22
+
23
+
24
+ specify "should have an up to date MAJOR version" do
25
+ EC2::VERSION::MAJOR.should.equal @major
26
+ end
27
+
28
+
29
+ specify "should have an up to date MINOR version" do
30
+ EC2::VERSION::MINOR.should.equal @minor
31
+ end
32
+
33
+
34
+ specify "should have an up to date TINY version" do
35
+ EC2::VERSION::TINY.should.equal @tiny
36
+ end
37
+
38
+
39
+ specify "should return a proper version string when #STRING is called" do
40
+ EC2::VERSION::STRING.should.equal @string
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,20 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:grempe@rubyforge.org)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ %w[ test/unit rubygems test/spec mocha stubba ].each { |f|
12
+ begin
13
+ require f
14
+ rescue LoadError
15
+ abort "Unable to load required gem for test: #{f}"
16
+ end
17
+ }
18
+
19
+ require File.dirname(__FILE__) + '/../lib/EC2'
20
+
data/website/index.txt ADDED
@@ -0,0 +1,427 @@
1
+ h2. Amazon Web Services EC2 Ruby Gem
2
+
3
+ h2. → 'amazon-ec2'
4
+
5
+ h2. About
6
+
7
+ Amazon Web Services offers a compute power on demand capability known as the Elastic Compute Cloud (EC2). The server resources in the cloud can be provisioned on demand by making HTTP Query API calls to EC2.
8
+
9
+ This 'amazon-ec2' Ruby Gem is an interface library that can be used to interact with the Amazon EC2 system and control server resources on demand from your Ruby scripts, or from Ruby on Rails applications.
10
+
11
+
12
+ h2. What's new?
13
+
14
+ 20080331 - Gem version 0.2.9 Updated with initial support of the new Amazon Web Services 2008-02-01 public API. So far support has been added for the new 'Elastic IP' functionality.
15
+
16
+ 20080217 - This project's source code now only available from our master Git repository at GitHub. The Subversion repository at Rubyforge will be cleared but we'll still publish any new gem versions to Rubyforge so you can still easily install them. Unless you plan to work on the source code this should have no effect on you. Now you can browse, clone or fork from our Git repository at "http://github.com/grempe/amazon-ec2":http://github.com/grempe/amazon-ec2. Please let us know if you have patches you would like us to pull from your git repository.
17
+
18
+ This 0.2.0 + series represents a major re-write of this gem and contains contributions from several people who make use of this gem for their own applications. Trust us, its worth the pain of upgrading if you have been using an older version. Some of the major enhancements you will find are:
19
+
20
+ * Updated API version in the query API request to 2007-08-29, and added all known method calls
21
+ in this version of the API to the gem (including the new instance types(small, medium, large)).
22
+ Previous releases have kept pace with changes such as the addition of paid AMI support with
23
+ product codes, instance reboot, viewing of console output, NAT addressing and more!
24
+
25
+ * MAJOR library changes : THESE CHANGES ARE NOT BACKWARD COMPATIBLE!! You will need to update
26
+ the way in which you make calls, handle responses, and rescue exceptions from this library.
27
+ If you prefer not to make these changes you can feel free to continue to use the older version
28
+ of the gem. These older versions however will no longer be maintained.
29
+
30
+ * MAJOR refactoring of how methods calls are made. Now all methods are called with a simple hash
31
+ of arguments and none of them are positional. This feels much more "Ruby'ish".
32
+
33
+ * MAJOR refactoring of how responses are returned to users. No longer do you have to call the
34
+ .parse method, and no longer are you getting back simple arrays of information. Responses
35
+ now come in the form of OpenStruct objects that contain all of the data for an object in
36
+ Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an EC2::Response object
37
+ which inherits from OpenStruct. The return data from EC2, which is in XML form, is parsed
38
+ with XmlSimple and is used to directly construct the return data structure. This allows us
39
+ to know with some confidence that the data structure returned from AWS will always be consistent
40
+ with this library's responses. There is also an .xml attribute for each response object that lets you
41
+ see the full and complete XML response from AWS if that is useful to you.
42
+
43
+ * Added an exception framework which will now throw appropriate Ruby exceptions
44
+ that match those handed to us by Amazon EC2. ArgumentError exceptions will also
45
+ be thrown if you are making calls we know to be illegal or malformed. You should rescue
46
+ these exceptions in your application instead of parsing text responses. All exceptions
47
+ descend from EC2::Error. You can see them all in exceptions.rb in the gem install.
48
+
49
+ * Added a full suite of test/spec unit tests which currently cover 100% of the public methods
50
+ in this library. We have abot 92% code coverage according to rcov. This has greatly enhanced
51
+ the reliability of the library as well as our confidence in the code.
52
+ We used to have 0% test coverage. :-/
53
+
54
+ * Added an EC2 command shell : 'ec2sh' which can be called from anywhere and gives you
55
+ an interactive irb session with an EC2 connection pre-made for you as @ec2. You can use this
56
+ to interactively execute any command on EC2 that this library supports. Try @ec2.methods.sort
57
+ or @ec2.describe_images to test it out. You must first setup two shell environment variables
58
+ which contain your ACCESS_KEY_ID and SECRET_ACCESS_KEY for this to work. Otherwise an error
59
+ will be thrown when you try to start it. This is way cool and shamelessly borrowed from
60
+ Marcel Molina's fine AWS::S3 library.
61
+
62
+ * Removed .parse method as it is no longer needed or wanted.
63
+
64
+
65
+
66
+ h2. Installing
67
+
68
+ This gem follows the standard conventions for installation on any system with Ruby and RubyGems installed. If you have worked with gems before this will look very familiar.
69
+
70
+ h3. Installation pre-requisites
71
+
72
+ h4. "Amazon Web Services developer account":https://aws-portal.amazon.com/gp/aws/developer/registration/index.html.
73
+
74
+ You'll need an account with AWS in order to use this gem at all. That should be your first stop on this tour. Your account must also be enabled for Amazon EC2 usage. After signup you'll be provided with an 'Access Key ID' and a 'Secret Access Key'. These allow you to authenticate any API calls you make and ensure correct billing to you for usage of their service. Take note of these keys (and keep them safe and secret!).
75
+
76
+ h4. Gem Dependencies
77
+
78
+ The following gems should be installed automatically as part of your install of amazon-ec2. Most of them are testing or build dependencies but they should be painless to install even if you don't plan on running the tests or building this gem manually on your own.
79
+
80
+ "XmlSimple":http://xml-simple.rubyforge.org/ (required)
81
+
82
+ "Mocha":http://mocha.rubyforge.org/ (optional for testing)
83
+
84
+ "Rcov":http://eigenclass.org/hiki.rb?rcov (optional for testing)
85
+
86
+ "Test-Spec":http://test-spec.rubyforge.org/test-spec/ (optional for testing)
87
+
88
+ "Syntax":http://syntax.rubyforge.org/ (optional for building your own copy of the gem and its docs)
89
+
90
+ "RedCloth":http://whytheluckystiff.net/ruby/redcloth (optional for building your own copy of the gem and its docs)
91
+
92
+
93
+ h3. Installing the gem
94
+
95
+ Linux / OS X : <pre syntax="ruby">sudo gem install amazon-ec2 --include-dependencies</pre>
96
+
97
+ Microsoft Windows : <pre syntax="ruby">gem install amazon-ec2 --include-dependencies</pre>
98
+
99
+
100
+ h2. Using the library
101
+
102
+ h3. Setting up...
103
+
104
+ The 'ec2sh' and 'ec2-gem-example.rb' scripts which will be introduced to you shortly expect your AWS EC2 credentials to
105
+ be stored as shell environment variables which are accessible to those scripts. This makes them convenient to use whenever
106
+ you need to do a quick query to see what images you have available to you, whats running now, or to start or stop an
107
+ instance on EC2. You'll find 'ec2sh' to be a very handy tool. I'll describe only the OS X route for setting up (of course
108
+ the setup steps will vary depending on your particular system and preferred shell). If you don't want to
109
+ do it this way, feel free to copy these scripts from the gem dir to any location where you can run them from and modify them directly to include your credentials.
110
+
111
+ h4. OS X Setup
112
+
113
+ Edit the file ~/.bash_login and add the following to the existing contents:
114
+
115
+ <pre syntax="ruby">
116
+
117
+ export RUBYOPT="rubygems"
118
+
119
+ # For amazon-ec2 and amazon s3 ruby gems
120
+ export AMAZON_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
121
+ export AMAZON_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID"
122
+
123
+ </pre>
124
+
125
+ Once you save the file you should close and re-open your command terminal so the new variables are made available. You'll need to do this close/re-open step for each terminal window you have open (or issue the 'source ~/.bash_login' command in each). Make sure that this file is only readable by your user so you don't inadvertantly expose your credentials to other users on your system.
126
+
127
+ You can verify that this setup is complete by running the 'set' in a command window and seeing that your credentials are in the list of shell variables.
128
+
129
+ h3. The basics...
130
+
131
+ The library exposes one main interface module <pre syntax="ruby">EC2::Base</pre>
132
+
133
+ This method requires arguments which include your AWS credentials and it will return an object that you can use to make
134
+ method calls directly against EC2. All the operations for using the EC2 service, including query string header signing,
135
+ are handled automatically for you. The connection string will look something like this:
136
+
137
+ <pre syntax="ruby">
138
+ @ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
139
+ </pre>
140
+
141
+ We have tried to keep the public methods on 'amazon-ec2' as close as possible to the AWS EC2 Query API.
142
+ This similarity allows you to reference the Query API Reference in the "EC2 Developer Guide":http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84 and be able to get started right away.
143
+ In most cases the methods names only differ in how they are presented. e.g. 'DescribeImages' becomes '#describe_images() in Ruby.
144
+ Feel free to browse the full "RDoc documentation":http://amazon-ec2.rubyforge.org/rdoc/ for all classes and methods of 'amazon-ec2' if you want more details.
145
+
146
+
147
+ h3. Examples
148
+
149
+ The best way to become familiar with 'amazon-ec2' is to take it for a test drive. We have provided a few simple ways to get you started. There is also some sample code below that should help out in using 'amazon-ec2' with a plain Ruby script, or as part of a Ruby on Rails application.
150
+
151
+
152
+ h4. Using the 'ec2-gem-example.rb' sample test script
153
+
154
+ An example Ruby script which exercises the library a bit more is installed for you to check out when you install this gem. You can run this script to verify that everything is setup and working correctly in your environment. Consult the file which is installed at :
155
+
156
+ <pre syntax="ruby">[your amazon-ec2 gem dir]/examples/ec2-example.rb</pre>
157
+
158
+ Since we also package this sample file in the gem's bin/ dir you should also be able to run it from anywhere on your shell path (once you have set your environment variables as described above).
159
+
160
+
161
+ h4. Using the 'ec2sh' command shell
162
+
163
+ The 'ec2sh' command shell is actually a standard 'irb' Ruby shell, with the main difference being we read your AWS credentials from your environment and pre-configure a connection string for you. This lets you run any EC2 command very simply. This has proven to be a valuable tool during the development of this gem and you should try it out. Since we install this tool in your system path as part of the installation of this gem, you should be able to simply run 'ec2sh' from any terminal command prompt on your local system. You'll see some basic instructions for use, and a few examples when you start 'ec2sh'. Go ahead and try it out now. We'll wait...
164
+
165
+ If your not in front of a terminal shell now (perhaps you're browsing this site on your iPhone) this is what you would see:
166
+
167
+ <pre syntax="ruby">
168
+
169
+ hostname:/tmp/rails/amazon_test glenn$ ec2sh
170
+
171
+ 'ec2sh' usage :
172
+ This is an interactive 'irb' command shell that allows you to use all
173
+ commands available to the amazon-ec2 gem. You'll find this to be a
174
+ great tool to help you debug issues and practice running commands
175
+ against the live EC2 servers prior to putting them in your code.
176
+
177
+ The EC2 connection is wired to the class instance '@ec2'. Make method calls
178
+ on this to execute commands on EC2. Adding a #to_s
179
+ at the end of any command should give you a full String representation of the
180
+ response. The #xml data is available for each response
181
+ which allows you to view the full and complete XML response returned by
182
+ EC2 without any parsing applied. This is useful for viewing the
183
+ hierarchy of an entire response in a friendly way (if XML is friendly
184
+ to you!). Understanding the hierarchy of the XML response is critical
185
+ to making effective use of this library.
186
+
187
+ Examples to try:
188
+
189
+ returns : all ec2 public methods
190
+ >> @ec2.methods.sort
191
+
192
+ returns : a string representation of ALL images
193
+ >> @ec2.describe_images.to_s
194
+
195
+ returns : an Array of EC2::Response objects, each an EC2 image and its data
196
+ >> @ec2.describe_images.imagesSet.item
197
+ >> @ec2.describe_images.imagesSet.item[0] (an OpenStruct of a single item in that array)
198
+ >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that OpenStruct item)
199
+
200
+ returns : an XML representation of all images
201
+ >> puts @ec2.describe_images.xml
202
+
203
+ returns : an XML representation of all images owned by Amazon
204
+ >> puts @ec2.describe_images(:owner_id => 'amazon').xml
205
+
206
+ >> @ec2.describe_images.imagesSet.item[0].to_s
207
+ => "#<EC2::Response:0x100A465B4 imageId=\"ami-018e6b68\" imageLocation=\"rbuilder-online/phonehome-1.5.6-x86_10132.img.manifest.xml\" imageOwnerId=\"099034111737\" imageState=\"available\" isPublic=\"true\" parent=#<EC2::Response:0x100A469A6 ...>>"
208
+
209
+ </pre>
210
+
211
+
212
+ h4. Using 'amazon-ec2' in Ruby scripts
213
+
214
+ Try out the following bit of code. This should walk through each image returned by a call to #describe_images and print out its key data. Note in the example below that you cannot walk through the results of the #describe_images call with the '.each' iterator (You'll get errors if you try). You need to instead walk through the Array of items which are in the 'imagesSet' embedded in the response. This reflects exactly the XML hierarchy of data returned from EC2 which we parse to Ruby OpenStruct objects (EC2::Response).
215
+
216
+ <pre syntax="ruby">
217
+ #!/usr/bin/env ruby
218
+
219
+ require 'rubygems'
220
+ require 'ec2'
221
+
222
+ ACCESS_KEY_ID = '--YOUR AWS ACCESS KEY ID--'
223
+ SECRET_ACCESS_KEY = '--YOUR AWS SECRET ACCESS KEY--'
224
+
225
+ ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
226
+
227
+ puts "----- listing images owned by 'amazon' -----"
228
+ ec2.describe_images(:owner_id => "amazon").imagesSet.item.each do |image|
229
+ # OpenStruct objects have members!
230
+ image.members.each do |member|
231
+ puts "#{member} => #{image[member]}"
232
+ end
233
+ end
234
+ </pre>
235
+
236
+
237
+ h4. Using 'amazon-ec2' in Ruby on Rails applications
238
+
239
+ in config/environment.rb:
240
+
241
+ <pre syntax="ruby">
242
+ # Require the amazon-ec2 gem and make its methods available in your Rails app
243
+ # Put this at the bottom of your environment.rb
244
+ require 'EC2'
245
+ </pre>
246
+
247
+ in app/controllers/your_controller.rb:
248
+ <pre syntax="ruby">
249
+
250
+ [some controller code ...]
251
+
252
+ ec2 = EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY")
253
+
254
+ # get ALL public images
255
+ @ec2_images = ec2.describe_images().imagesSet.item
256
+
257
+ # Get info on all public EC2 images created by the Amazon EC2 team.
258
+ @ec2_images_amazon = ec2.describe_images(:owner_id => "amazon").imagesSet.item
259
+
260
+ [some more controller code ...]
261
+
262
+ </pre>
263
+
264
+ and then you can show off your EC2 image data with some code in app/views/your_view.rhtml:
265
+
266
+ <pre syntax="ruby">
267
+
268
+ <h1>EC2 Test#index</h1>
269
+
270
+ <h1>Sample 1 - debug() view</h1>
271
+
272
+ <%= debug(@ec2_images_amazon) %>
273
+
274
+ <h1>Sample 2 - Build a table</h1>
275
+
276
+ <table border='1'>
277
+ <tr>
278
+ <th>image.imageId</th>
279
+ <th>image.imageLocation</th>
280
+ <th>image.imageOwnerId</th>
281
+ <th>image.imageState</th>
282
+ <th>image.isPublic</th>
283
+ </tr>
284
+
285
+ <% for image in @ec2_images_amazon %>
286
+ <tr>
287
+ <td><%=h image.imageId %></td>
288
+ <td><%=h image.imageLocation %></td>
289
+ <td><%=h image.imageOwnerId %></td>
290
+ <td><%=h image.imageState %></td>
291
+ <td><%=h image.isPublic %></td>
292
+ </tr>
293
+ <% end %>
294
+ </table>
295
+
296
+ <h1>Sample 3 - Iterate</h1>
297
+
298
+ <% @ec2_images_amazon.each do |image| %>
299
+ <% image.each_pair do |key, value| %>
300
+ <% unless key == 'parent' %>
301
+ <%= "#{key} => #{value}" %><br />
302
+ <% end %>
303
+ <% end %>
304
+ <br />
305
+ <% end %>
306
+
307
+ </pre>
308
+
309
+
310
+ h4. Important notes regarding the structure of EC2::Response Objects
311
+
312
+ One of the key benefits of this new version of the library is that all responses from EC2 are bundled up in
313
+ a real data structure and no longer require parsing of text. We use an OpenStruct as the parent for the EC2::Response
314
+ object and we populate it directly from the XML given to us by EC2 in response to any command we issue. This means that
315
+ future changes to the API and what is returned by EC2 will largely be handled transparently by the gem. This is a huge
316
+ benefit. What this means though, is that you may have to do a little homework on what actually gets returned by EC2 as XML.
317
+ For example, when you make a #describe_images call in ec2sh to EC2 what you will get back will look like:
318
+
319
+
320
+ <pre syntax="ruby">
321
+ $ ec2sh
322
+ >> puts @ec2.describe_images(:owner_id => 'amazon').xml
323
+
324
+ <?xml version="1.0"?>
325
+ <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-19/">
326
+ <imagesSet>
327
+ <item>
328
+ <imageId>ami-20b65349</imageId>
329
+ <imageLocation>ec2-public-images/fedora-core4-base.manifest.xml</imageLocation>
330
+ <imageState>available</imageState>
331
+ <imageOwnerId>amazon</imageOwnerId>
332
+ <isPublic>true</isPublic>
333
+ </item>
334
+ <item>
335
+ <imageId>ami-22b6534b</imageId>
336
+ <imageLocation>ec2-public-images/fedora-core4-mysql.manifest.xml</imageLocation>
337
+ <imageState>available</imageState>
338
+ <imageOwnerId>amazon</imageOwnerId>
339
+ <isPublic>true</isPublic>
340
+ </item>
341
+ <item>
342
+ <imageId>ami-23b6534a</imageId>
343
+ <imageLocation>ec2-public-images/fedora-core4-apache.manifest.xml</imageLocation>
344
+ <imageState>available</imageState>
345
+ <imageOwnerId>amazon</imageOwnerId>
346
+ <isPublic>true</isPublic>
347
+ </item>
348
+ <item>
349
+ <imageId>ami-25b6534c</imageId>
350
+ <imageLocation>ec2-public-images/fedora-core4-apache-mysql.manifest.xml</imageLocation>
351
+ <imageState>available</imageState>
352
+ <imageOwnerId>amazon</imageOwnerId>
353
+ <isPublic>true</isPublic>
354
+ </item>
355
+ <item>
356
+ <imageId>ami-26b6534f</imageId>
357
+ <imageLocation>ec2-public-images/developer-image.manifest.xml</imageLocation>
358
+ <imageState>available</imageState>
359
+ <imageOwnerId>amazon</imageOwnerId>
360
+ <isPublic>true</isPublic>
361
+ </item>
362
+ <item>
363
+ <imageId>ami-2bb65342</imageId>
364
+ <imageLocation>ec2-public-images/getting-started.manifest.xml</imageLocation>
365
+ <imageState>available</imageState>
366
+ <imageOwnerId>amazon</imageOwnerId>
367
+ <isPublic>true</isPublic>
368
+ </item>
369
+ </imagesSet>
370
+ </DescribeImagesResponse>
371
+
372
+ </pre>
373
+
374
+ You can see in the XML the structure that you will need to follow when constructing queries for information and parsing responses from EC2.
375
+
376
+ So, for example, if you wanted to get the image ID of the third image listed in the response above you would need to do:
377
+
378
+ <pre syntax="ruby">
379
+ >> puts @ec2.describe_images(:owner_id => 'amazon').imagesSet.item[2].imageId
380
+ ami-23b6534a
381
+ </pre>
382
+
383
+ EC2 will typically return 'sets' of things (imagesSet, reservationSet, etc.) which we map to ruby Arrays (.imagesSet.item in the example above). If you want to iterate over a response set you will need to iterate over this array. The Arrays will typically contain additional EC2::Response objects that represent each individual item. You'll find that you can use the 'ec2sh' to help you understand the structure more completely if you try issuing commands there as a way to practice seeing what will be returned and making sure you get exactly what you want. You can always call the EC2::Response#xml method like I did above to see the exact XML returned which allows you to easily derive the structure for the Ruby OpenStruct object.
384
+
385
+
386
+ h2. Contributing
387
+
388
+ We can always use your help! Do you have Ruby skills? Do you see a bug or enhancement that you'd like to see fixed? We would love to have your patches for documentation, test cases, or enhancements.
389
+
390
+ h2. Project Info
391
+
392
+ This project is managed as a RubyForge project which you can find at "http://amazon-ec2.rubyforge.org/":http://amazon-ec2.rubyforge.org/ and this is always the best place to find the latest news, report any bugs, or submit feature requests. If you are interesting in viewing or working with the source code you can find everything you need at : "http://github.com/grempe/amazon-ec2":http://github.com/grempe/amazon-ec2.
393
+
394
+ h2. Learning More
395
+
396
+ h3. Documentation
397
+
398
+ Complete RDoc generated documentation can be found at "http://amazon-ec2.rubyforge.org/rdoc/":http://amazon-ec2.rubyforge.org/rdoc/
399
+
400
+ h3. Websites
401
+
402
+ "Amazon Web Services Home":http://aws.amazon.com/
403
+ "Project Home":http://rubyforge.org/projects/amazon-ec2/
404
+ "Downloads":http://rubyforge.org/frs/?group_id=2753
405
+ "Browse Code":http://github.com/grempe/amazon-ec2
406
+ "Report Bugs":http://rubyforge.org/tracker/?group_id=2753
407
+ "Request Features":http://rubyforge.org/tracker/?group_id=2753
408
+ "Submit Patches":http://rubyforge.org/tracker/?group_id=2753
409
+
410
+
411
+ h3. Related Projects
412
+
413
+ "Capsize":http://capsize.rubyforge.org/ : A Capistrano (>= 2.x) plugin that allows complete control of Amazon EC2 from Capistrano recipes.
414
+
415
+
416
+ h2. Credits
417
+
418
+ The original sample code for this library was provided by Amazon Web Services, LLC. Thanks to them for providing all of us with samples that got this started. This latest version of amazon-ec2 doesn't much resemble the original. They got us going though and thanks to the EC2 team for including Ruby in their plans. We hope to see more AWS Ruby code.
419
+
420
+ Thanks to all the great folks who submitted patches and kept this project rolling. I would especially like to thank Sean Knapp, Kevin Clark, and Randy Bias. Your patches and help are much appreciated.
421
+
422
+ Thanks to Dr. Nic Williams and his great 'NewGem' Ruby Gem Generator. This gem of a Gem helped me package up this code for distribution in a flash! You can find Dr. Nic's NewGem generator at "http://newgem.rubyforge.org/":http://newgem.rubyforge.org/
423
+
424
+
425
+ h2. Contact
426
+
427
+ Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.