amazon-ec2 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -1
- data/License.txt +66 -67
- data/Manifest.txt +18 -9
- data/Rakefile +4 -142
- data/bin/ec2-gem-example.rb +1 -1
- data/bin/ec2sh +1 -1
- data/bin/setup.rb +1 -1
- data/config/hoe.rb +76 -0
- data/config/requirements.rb +17 -0
- data/lib/EC2.rb +1 -1
- data/lib/EC2/console.rb +1 -1
- data/lib/EC2/exceptions.rb +1 -1
- data/lib/EC2/image_attributes.rb +1 -1
- data/lib/EC2/images.rb +1 -1
- data/lib/EC2/instances.rb +1 -1
- data/lib/EC2/keypairs.rb +1 -1
- data/lib/EC2/products.rb +1 -1
- data/lib/EC2/responses.rb +1 -1
- data/lib/EC2/security_groups.rb +1 -1
- data/lib/EC2/version.rb +2 -2
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/{scripts → script}/txt2html +10 -3
- data/tasks/deployment.rake +27 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_EC2.rb +1 -1
- data/test/test_EC2_console.rb +1 -1
- data/test/test_EC2_image_attributes.rb +1 -1
- data/test/test_EC2_images.rb +1 -1
- data/test/test_EC2_instances.rb +1 -1
- data/test/test_EC2_keypairs.rb +1 -1
- data/test/test_EC2_products.rb +1 -1
- data/test/test_EC2_responses.rb +1 -1
- data/test/test_EC2_security_groups.rb +1 -1
- data/test/test_EC2_version.rb +2 -2
- data/test/test_helper.rb +1 -1
- data/website/announce.html +109 -0
- data/website/announce.txt +36 -0
- data/website/index.html +155 -145
- data/website/stylesheets/screen.css +16 -7
- data/website/template.rhtml +1 -1
- metadata +23 -14
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
http://amazon-ec2.rubyforge.org/
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Hello Ruby'ists,
|
|
7
|
+
|
|
8
|
+
I wanted to announce the availability of a major new release (version 0.2.2) of the open source 'amazon-ec2' Ruby Gem. This is for Ruby/Ruby on Rails developers that want their applications to interface with EC2.
|
|
9
|
+
|
|
10
|
+
http://amazon-ec2.rubyforge.org/
|
|
11
|
+
|
|
12
|
+
The original release of this gem (<= 0.1.0 about six months ago) was based on the original sample code provided by the AWS team (Thanks guys!). This new release represents an almost complete re-write of that code and should prove to be much more reliable, easier to use, and feature complete.
|
|
13
|
+
|
|
14
|
+
Important : Please note that this is such a major re-write that we were not able to maintain backwards compatibility with the older versions of the gem. So if you are using a version of 'amazon-ec2' that is less than v 0.2.2 you should carefully read the docs before you upgrade as you will be required to update your code. You will also want to exercise caution if you are actively using the 'Capazon' gem. 'Capazon' has been deprecated and we'll have more news on that topic soon. If this is your first install and use of the gem then you are good to go!
|
|
15
|
+
|
|
16
|
+
Some of the major changes are:
|
|
17
|
+
|
|
18
|
+
* Re-factored all methods to use Ruby Hashes for all parameters. Makes figuring out what options to pass and actually passing them much much easier. Order of params no longer matters and your code will be self documenting when you can read the hash key names for each parameter.
|
|
19
|
+
|
|
20
|
+
* All responses from EC2 are now sent back as an EC2::Response object. This is an OpenStruct object that contains everything in the EC2 XML response converted to a real Ruby object data structure. No more parsing responses or error responses. The OpenStruct object is created using XmlSimple and is a one-to-one mapping of the structure in the EC2 response XML.
|
|
21
|
+
|
|
22
|
+
* A complete exception handling framework has been added. Any exception (either from incorrect args, or as part of the response from EC2) now throw real Ruby exceptions that are subclassed from EC2::Error. All of the exceptions defined by AWS in the developer guide each have their own exception sub-class. This lets you handle exceptions on a case by case basis with a great degree of granularity. Just wrap any calls to EC2 using the gem in a begin/rescue clause. There are no longer any errors that will come back in some kind of text form. Either the command is OK and you get an EC2::Response object, or their is a problem and you get EC2::Error or one of its sub-classes.
|
|
23
|
+
|
|
24
|
+
* The gem now has a full unit test suite with several hundred test cases. All public methods on the gem have 100% test case coverage, and the overall code coverage according to rcov is 92%. This has provided us with a much more robust gem and should help us avoid future regression errors with new releases.
|
|
25
|
+
|
|
26
|
+
* The gem is now up to date with the latest version of the EC2 API (2007-01-19) and all API methods should be covered. This includes new additions such as the ability to get console output, reboot instances, and running instances with the new NAT addressing scheme.
|
|
27
|
+
|
|
28
|
+
* The rdocs, website, and README have undergone significant surgery. The website content is now automatically generated as part of the build and deploy of the gem.
|
|
29
|
+
|
|
30
|
+
I encourage you to visit the link above for the full information about what's new and why you may want to think about transitioning to this new release. A lot of work by a handful of people has gone into this new release and we hope you enjoy it. Stand by for some more news regarding using this gem with Capistrano in the near future.
|
|
31
|
+
|
|
32
|
+
Enjoy, and please feel free to reach out to me with any questions at grempe -at- rubyforge -dot- org.
|
|
33
|
+
|
|
34
|
+
Glenn
|
|
35
|
+
|
|
36
|
+
|
data/website/index.html
CHANGED
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
|
|
33
33
|
<h1>Amazon Web Services EC2 Ruby Gem</h1>
|
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/amazon-ec2"; return false'>
|
|
35
|
-
Get Version
|
|
36
|
-
<a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.2.
|
|
35
|
+
<p>Get Version</p>
|
|
36
|
+
<a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.2.5</a>
|
|
37
37
|
</div>
|
|
38
38
|
<h2>→ ‘amazon-ec2’</h2>
|
|
39
39
|
|
|
@@ -174,10 +174,10 @@ Marcel Molina’s fine <span class="caps">AWS</span>::S3 library.</li>
|
|
|
174
174
|
<h3>Installing the gem</h3>
|
|
175
175
|
|
|
176
176
|
|
|
177
|
-
<p>Linux / <span class="caps">OS X</span> : <pre syntax="
|
|
177
|
+
<p>Linux / <span class="caps">OS X</span> : <pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">amazon</span><span class="punct">-</span><span class="ident">ec2</span> <span class="punct">--</span><span class="ident">include</span><span class="punct">-</span><span class="ident">dependencies</span></pre></p>
|
|
178
178
|
|
|
179
179
|
|
|
180
|
-
<p>Microsoft Windows : <pre syntax="
|
|
180
|
+
<p>Microsoft Windows : <pre class='syntax'><span class="ident">gem</span> <span class="ident">install</span> <span class="ident">amazon</span><span class="punct">-</span><span class="ident">ec2</span> <span class="punct">--</span><span class="ident">include</span><span class="punct">-</span><span class="ident">dependencies</span></pre></p>
|
|
181
181
|
|
|
182
182
|
|
|
183
183
|
<h2>Using the library</h2>
|
|
@@ -200,15 +200,16 @@ do it this way, feel free to copy these scripts from the gem dir to any location
|
|
|
200
200
|
<p>Edit the file ~/.bash_login and add the following to the existing contents:</p>
|
|
201
201
|
|
|
202
202
|
|
|
203
|
-
<pre syntax
|
|
203
|
+
<p><pre class='syntax'>
|
|
204
204
|
|
|
205
|
-
export RUBYOPT="rubygems"
|
|
205
|
+
<span class="ident">export</span> <span class="constant">RUBYOPT</span><span class="punct">="</span><span class="string">rubygems</span><span class="punct">"</span>
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
export AMAZON_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
|
|
209
|
-
export AMAZON_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID"
|
|
207
|
+
<span class="comment"># For amazon-ec2 and amazon s3 ruby gems</span>
|
|
208
|
+
<span class="ident">export</span> <span class="constant">AMAZON_ACCESS_KEY_ID</span><span class="punct">="</span><span class="string">YOUR_ACCESS_KEY_ID</span><span class="punct">"</span>
|
|
209
|
+
<span class="ident">export</span> <span class="constant">AMAZON_SECRET_ACCESS_KEY</span><span class="punct">="</span><span class="string">YOUR_SECRET_ACCESS_KEY_ID</span><span class="punct">"</span>
|
|
210
|
+
|
|
211
|
+
</pre></p>
|
|
210
212
|
|
|
211
|
-
</pre>
|
|
212
213
|
|
|
213
214
|
<p>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.</p>
|
|
214
215
|
|
|
@@ -219,7 +220,7 @@ export AMAZON_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID"
|
|
|
219
220
|
<h3>The basics…</h3>
|
|
220
221
|
|
|
221
222
|
|
|
222
|
-
<p>The library exposes one main interface module <pre syntax="
|
|
223
|
+
<p>The library exposes one main interface module <pre class='syntax'><span class="constant">EC2</span><span class="punct">::</span><span class="constant">Base</span></pre></p>
|
|
223
224
|
|
|
224
225
|
|
|
225
226
|
<p>This method requires arguments which include your <span class="caps">AWS</span> credentials and it will return an object that you can use to make
|
|
@@ -227,9 +228,10 @@ method calls directly against <span class="caps">EC2</span>. All the operations
|
|
|
227
228
|
are handled automatically for you. The connection string will look something like this:</p>
|
|
228
229
|
|
|
229
230
|
|
|
230
|
-
<pre syntax
|
|
231
|
-
|
|
232
|
-
</pre>
|
|
231
|
+
<p><pre class='syntax'>
|
|
232
|
+
<span class="attribute">@ec2</span> <span class="punct">=</span> <span class="constant">EC2</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="symbol">:access_key_id</span> <span class="punct">=></span> <span class="constant">ACCESS_KEY_ID</span><span class="punct">,</span> <span class="symbol">:secret_access_key</span> <span class="punct">=></span> <span class="constant">SECRET_ACCESS_KEY</span><span class="punct">)</span>
|
|
233
|
+
</pre></p>
|
|
234
|
+
|
|
233
235
|
|
|
234
236
|
<p>We have tried to keep the public methods on ‘amazon-ec2’ as close as possible to the <span class="caps">AWS EC2</span> Query <span class="caps">API</span>.
|
|
235
237
|
This similarity allows you to reference the Query <span class="caps">API</span> Reference in the <a href="http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84"><span class="caps">EC2</span> Developer Guide</a> and be able to get started right away.
|
|
@@ -249,7 +251,8 @@ Feel free to browse the full <a href="http://amazon-ec2.rubyforge.org/rdoc/">RDo
|
|
|
249
251
|
<p>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 :</p>
|
|
250
252
|
|
|
251
253
|
|
|
252
|
-
<pre syntax="
|
|
254
|
+
<p><pre class='syntax'><span class="punct">[</span><span class="ident">your</span> <span class="ident">amazon</span><span class="punct">-</span><span class="ident">ec2</span> <span class="ident">gem</span> <span class="ident">dir</span><span class="punct">]/</span><span class="ident">examples</span><span class="punct">/</span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">example</span><span class="punct">.</span><span class="ident">rb</span></pre></p>
|
|
255
|
+
|
|
253
256
|
|
|
254
257
|
<p>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).</p>
|
|
255
258
|
|
|
@@ -263,17 +266,17 @@ Feel free to browse the full <a href="http://amazon-ec2.rubyforge.org/rdoc/">RDo
|
|
|
263
266
|
<p>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:</p>
|
|
264
267
|
|
|
265
268
|
|
|
266
|
-
<pre syntax
|
|
269
|
+
<p><pre class='syntax'>
|
|
267
270
|
|
|
268
|
-
hostname
|
|
269
|
-
|
|
270
|
-
'ec2sh' usage
|
|
271
|
-
This is an interactive 'irb' command shell that allows you to use all
|
|
272
|
-
commands available to the amazon
|
|
271
|
+
<span class="ident">hostname</span><span class="punct">:/</span><span class="regex">tmp</span><span class="punct">/</span><span class="ident">rails</span><span class="punct">/</span><span class="ident">amazon_test</span> <span class="ident">glenn</span><span class="global">$ </span><span class="ident">ec2sh</span>
|
|
272
|
+
|
|
273
|
+
<span class="punct">'</span><span class="string">ec2sh</span><span class="punct">'</span> <span class="ident">usage</span> <span class="punct">:</span>
|
|
274
|
+
<span class="constant">This</span> <span class="ident">is</span> <span class="ident">an</span> <span class="ident">interactive</span> <span class="punct">'</span><span class="string">irb</span><span class="punct">'</span> <span class="ident">command</span> <span class="ident">shell</span> <span class="ident">that</span> <span class="ident">allows</span> <span class="ident">you</span> <span class="ident">to</span> <span class="ident">use</span> <span class="ident">all</span>
|
|
275
|
+
<span class="ident">commands</span> <span class="ident">available</span> <span class="ident">to</span> <span class="ident">the</span> <span class="ident">amazon</span><span class="punct">-</span><span class="ident">ec2</span> <span class="ident">gem</span><span class="punct">.</span> <span class="ident">You</span><span class="punct">'</span><span class="string">ll find this to be a
|
|
273
276
|
great tool to help you debug issues and practice running commands
|
|
274
277
|
against the live EC2 servers prior to putting them in your code.
|
|
275
|
-
|
|
276
|
-
The EC2 connection is wired to the class instance '
|
|
278
|
+
|
|
279
|
+
The EC2 connection is wired to the class instance </span><span class="punct">'</span><span class="attribute">@ec2</span><span class="punct">'</span><span class="string">. Make method calls
|
|
277
280
|
on this to execute commands on EC2. Adding a #to_s
|
|
278
281
|
at the end of any command should give you a full String representation of the
|
|
279
282
|
response. The #xml data is available for each response
|
|
@@ -282,30 +285,31 @@ hostname:/tmp/rails/amazon_test glenn$ ec2sh
|
|
|
282
285
|
hierarchy of an entire response in a friendly way (if XML is friendly
|
|
283
286
|
to you!). Understanding the hierarchy of the XML response is critical
|
|
284
287
|
to making effective use of this library.
|
|
285
|
-
|
|
288
|
+
|
|
286
289
|
Examples to try:
|
|
287
|
-
|
|
290
|
+
|
|
288
291
|
returns : all ec2 public methods
|
|
289
292
|
>> @ec2.methods.sort
|
|
290
|
-
|
|
293
|
+
|
|
291
294
|
returns : a string representation of ALL images
|
|
292
295
|
>> @ec2.describe_images.to_s
|
|
293
|
-
|
|
296
|
+
|
|
294
297
|
returns : an Array of EC2::Response objects, each an EC2 image and its data
|
|
295
298
|
>> @ec2.describe_images.imagesSet.item
|
|
296
299
|
>> @ec2.describe_images.imagesSet.item[0] (an OpenStruct of a single item in that array)
|
|
297
300
|
>> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that OpenStruct item)
|
|
298
|
-
|
|
301
|
+
|
|
299
302
|
returns : an XML representation of all images
|
|
300
303
|
>> puts @ec2.describe_images.xml
|
|
301
|
-
|
|
304
|
+
|
|
302
305
|
returns : an XML representation of all images owned by Amazon
|
|
303
|
-
>> puts @ec2.describe_images(:owner_id => 'amazon').xml
|
|
304
|
-
|
|
306
|
+
>> puts @ec2.describe_images(:owner_id => </span><span class="punct">'</span><span class="ident">amazon</span><span class="punct">'</span><span class="string">).xml
|
|
307
|
+
|
|
305
308
|
>> @ec2.describe_images.imagesSet.item[0].to_s
|
|
306
|
-
=>
|
|
309
|
+
=> "#<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 ...>>"
|
|
310
|
+
<span class="normal">
|
|
311
|
+
</span></span></pre></p>
|
|
307
312
|
|
|
308
|
-
</pre>
|
|
309
313
|
|
|
310
314
|
<h4>Using ‘amazon-ec2’ in Ruby scripts</h4>
|
|
311
315
|
|
|
@@ -313,25 +317,26 @@ hostname:/tmp/rails/amazon_test glenn$ ec2sh
|
|
|
313
317
|
<p>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 <span class="caps">XML</span> hierarchy of data returned from <span class="caps">EC2</span> which we parse to Ruby OpenStruct objects (EC2::Response).</p>
|
|
314
318
|
|
|
315
319
|
|
|
316
|
-
<pre syntax
|
|
317
|
-
|
|
320
|
+
<p><pre class='syntax'>
|
|
321
|
+
<span class="comment">#!/usr/bin/env ruby</span>
|
|
318
322
|
|
|
319
|
-
require 'rubygems'
|
|
320
|
-
require 'ec2'
|
|
323
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
|
|
324
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">ec2</span><span class="punct">'</span>
|
|
321
325
|
|
|
322
|
-
ACCESS_KEY_ID = '
|
|
323
|
-
SECRET_ACCESS_KEY = '
|
|
326
|
+
<span class="constant">ACCESS_KEY_ID</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">--YOUR AWS ACCESS KEY ID--</span><span class="punct">'</span>
|
|
327
|
+
<span class="constant">SECRET_ACCESS_KEY</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">--YOUR AWS SECRET ACCESS KEY--</span><span class="punct">'</span>
|
|
328
|
+
|
|
329
|
+
<span class="ident">ec2</span> <span class="punct">=</span> <span class="constant">EC2</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="symbol">:access_key_id</span> <span class="punct">=></span> <span class="constant">ACCESS_KEY_ID</span><span class="punct">,</span> <span class="symbol">:secret_access_key</span> <span class="punct">=></span> <span class="constant">SECRET_ACCESS_KEY</span><span class="punct">)</span>
|
|
330
|
+
|
|
331
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string">----- listing images owned by 'amazon' -----</span><span class="punct">"</span>
|
|
332
|
+
<span class="ident">ec2</span><span class="punct">.</span><span class="ident">describe_images</span><span class="punct">(</span><span class="symbol">:owner_id</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">amazon</span><span class="punct">").</span><span class="ident">imagesSet</span><span class="punct">.</span><span class="ident">item</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">image</span><span class="punct">|</span>
|
|
333
|
+
<span class="comment"># OpenStruct objects have members!</span>
|
|
334
|
+
<span class="ident">image</span><span class="punct">.</span><span class="ident">members</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">member</span><span class="punct">|</span>
|
|
335
|
+
<span class="ident">puts</span> <span class="punct">"</span><span class="string"><span class="expr">#{member}</span> => <span class="expr">#{image[member]}</span></span><span class="punct">"</span>
|
|
336
|
+
<span class="keyword">end</span>
|
|
337
|
+
<span class="keyword">end</span>
|
|
338
|
+
</pre></p>
|
|
324
339
|
|
|
325
|
-
ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
|
|
326
|
-
|
|
327
|
-
puts "----- listing images owned by 'amazon' -----"
|
|
328
|
-
ec2.describe_images(:owner_id => "amazon").imagesSet.item.each do |image|
|
|
329
|
-
# OpenStruct objects have members!
|
|
330
|
-
image.members.each do |member|
|
|
331
|
-
puts "#{member} => #{image[member]}"
|
|
332
|
-
end
|
|
333
|
-
end
|
|
334
|
-
</pre>
|
|
335
340
|
|
|
336
341
|
<h4>Using ‘amazon-ec2’ in Ruby on Rails applications</h4>
|
|
337
342
|
|
|
@@ -339,58 +344,60 @@ end
|
|
|
339
344
|
<p>in config/environment.rb:</p>
|
|
340
345
|
|
|
341
346
|
|
|
342
|
-
<pre syntax
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
require 'EC2'
|
|
346
|
-
</pre>
|
|
347
|
+
<p><pre class='syntax'>
|
|
348
|
+
<span class="comment"># Require the amazon-ec2 gem and make its methods available in your Rails app</span>
|
|
349
|
+
<span class="comment"># Put this at the bottom of your environment.rb</span>
|
|
350
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">EC2</span><span class="punct">'</span>
|
|
351
|
+
</pre></p>
|
|
352
|
+
|
|
347
353
|
|
|
348
|
-
in app/controllers/your_controller.rb:
|
|
349
|
-
<pre syntax
|
|
354
|
+
<p>in app/controllers/your_controller.rb:
|
|
355
|
+
<pre class='syntax'>
|
|
350
356
|
|
|
351
|
-
[some controller code
|
|
357
|
+
<span class="punct">[</span><span class="ident">some</span> <span class="ident">controller</span> <span class="ident">code</span> <span class="punct">...]</span>
|
|
352
358
|
|
|
353
|
-
ec2 = EC2
|
|
359
|
+
<span class="ident">ec2</span> <span class="punct">=</span> <span class="constant">EC2</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="symbol">:access_key_id</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">YOUR_AWS_ACCESS_KEY_ID</span><span class="punct">",</span> <span class="symbol">:secret_access_key</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">YOUR_AWS_SECRET_ACCESS_KEY</span><span class="punct">")</span>
|
|
354
360
|
|
|
355
|
-
|
|
356
|
-
|
|
361
|
+
<span class="comment"># get ALL public images</span>
|
|
362
|
+
<span class="attribute">@ec2_images</span> <span class="punct">=</span> <span class="ident">ec2</span><span class="punct">.</span><span class="ident">describe_images</span><span class="punct">().</span><span class="ident">imagesSet</span><span class="punct">.</span><span class="ident">item</span>
|
|
357
363
|
|
|
358
|
-
|
|
359
|
-
|
|
364
|
+
<span class="comment"># Get info on all public EC2 images created by the Amazon EC2 team.</span>
|
|
365
|
+
<span class="attribute">@ec2_images_amazon</span> <span class="punct">=</span> <span class="ident">ec2</span><span class="punct">.</span><span class="ident">describe_images</span><span class="punct">(</span><span class="symbol">:owner_id</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">amazon</span><span class="punct">").</span><span class="ident">imagesSet</span><span class="punct">.</span><span class="ident">item</span>
|
|
360
366
|
|
|
361
|
-
[some more controller code
|
|
367
|
+
<span class="punct">[</span><span class="ident">some</span> <span class="ident">more</span> <span class="ident">controller</span> <span class="ident">code</span> <span class="punct">...]</span>
|
|
368
|
+
|
|
369
|
+
</pre></p>
|
|
362
370
|
|
|
363
|
-
</pre>
|
|
364
371
|
|
|
365
372
|
<p>and then you can show off your <span class="caps">EC2</span> image data with some code in app/views/your_view.rhtml:</p>
|
|
366
373
|
|
|
367
374
|
|
|
368
|
-
<pre syntax
|
|
375
|
+
<p><pre class='syntax'>
|
|
369
376
|
|
|
370
|
-
|
|
377
|
+
<span class="punct"><</span><span class="ident">h1</span><span class="punct">></span><span class="constant">EC2</span> <span class="constant">Test</span><span class="comment">#index</h1></span>
|
|
371
378
|
|
|
372
|
-
|
|
379
|
+
<span class="punct"><</span><span class="ident">h1</span><span class="punct">></span><span class="constant">Sample</span> <span class="number">1</span> <span class="punct">-</span> <span class="ident">debug</span><span class="punct">()</span> <span class="ident">view</span><span class="punct"></</span><span class="regex">h1>
|
|
373
380
|
|
|
374
381
|
<%= debug(@ec2_images_amazon) %>
|
|
375
382
|
|
|
376
|
-
<h1>Sample 2 - Build a table<
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
<th>image.imageLocation<
|
|
382
|
-
|
|
383
|
-
<th>image.imageState<
|
|
384
|
-
|
|
385
|
-
<
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
<tr
|
|
389
|
-
|
|
390
|
-
<td><
|
|
391
|
-
|
|
392
|
-
<td><
|
|
393
|
-
|
|
383
|
+
<h1>Sample 2 - Build a table<</span><span class="punct">/</span><span class="ident">h1</span><span class="punct">></span>
|
|
384
|
+
|
|
385
|
+
<span class="punct"><</span><span class="ident">table</span> <span class="ident">border</span><span class="punct">='</span><span class="string">1</span><span class="punct">'></span>
|
|
386
|
+
<span class="punct"><</span><span class="ident">tr</span><span class="punct">></span>
|
|
387
|
+
<span class="punct"><</span><span class="ident">th</span><span class="punct">></span><span class="ident">image</span><span class="punct">.</span><span class="ident">imageId</span><span class="punct"></</span><span class="regex">th>
|
|
388
|
+
<th>image.imageLocation<</span><span class="punct">/</span><span class="ident">th</span><span class="punct">></span>
|
|
389
|
+
<span class="punct"><</span><span class="ident">th</span><span class="punct">></span><span class="ident">image</span><span class="punct">.</span><span class="ident">imageOwnerId</span><span class="punct"></</span><span class="regex">th>
|
|
390
|
+
<th>image.imageState<</span><span class="punct">/</span><span class="ident">th</span><span class="punct">></span>
|
|
391
|
+
<span class="punct"><</span><span class="ident">th</span><span class="punct">></span><span class="ident">image</span><span class="punct">.</span><span class="ident">isPublic</span><span class="punct"></</span><span class="regex">th>
|
|
392
|
+
<</span><span class="punct">/</span><span class="ident">tr</span><span class="punct">></span>
|
|
393
|
+
|
|
394
|
+
<span class="punct"><%</span> <span class="keyword">for</span> <span class="ident">image</span> <span class="keyword">in</span> <span class="attribute">@ec2_images_amazon</span> <span class="punct">%></span><span class="string">
|
|
395
|
+
<tr</span><span class="punct">></span>
|
|
396
|
+
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.imageId %></td>
|
|
397
|
+
<td><%</span><span class="punct">=</span><span class="ident">h</span> <span class="ident">image</span><span class="punct">.</span><span class="ident">imageLocation</span> <span class="punct">%></span><span class="string"></td</span><span class="punct">></span>
|
|
398
|
+
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.imageOwnerId %></td>
|
|
399
|
+
<td><%</span><span class="punct">=</span><span class="ident">h</span> <span class="ident">image</span><span class="punct">.</span><span class="ident">imageState</span> <span class="punct">%></span><span class="string"></td</span><span class="punct">></span>
|
|
400
|
+
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.isPublic %></td>
|
|
394
401
|
</tr>
|
|
395
402
|
<% end %>
|
|
396
403
|
</table>
|
|
@@ -398,15 +405,16 @@ ec2 = EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_acces
|
|
|
398
405
|
<h1>Sample 3 - Iterate</h1>
|
|
399
406
|
|
|
400
407
|
<% @ec2_images_amazon.each do |image| %>
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
<% image.each_pair do |key, value| %>
|
|
409
|
+
<% unless key </span><span class="punct">==</span> <span class="punct">'</span><span class="string">parent</span><span class="punct">'</span> <span class="punct">%></span><span class="string">
|
|
410
|
+
<%= "<span class="expr">#{key}</span> =</span><span class="punct">></span> <span class="comment">#{value}" %><br /></span>
|
|
411
|
+
<span class="punct"><%</span> <span class="keyword">end</span> <span class="punct">%></span><span class="string">
|
|
412
|
+
<% end %</span><span class="punct">></span>
|
|
413
|
+
<span class="punct"><</span><span class="ident">br</span> <span class="punct">/></span>
|
|
414
|
+
<span class="punct"><%</span> <span class="keyword">end</span> <span class="punct">%></span><span class="string">
|
|
415
|
+
<span class="normal">
|
|
416
|
+
</span></span></pre></p>
|
|
408
417
|
|
|
409
|
-
</pre>
|
|
410
418
|
|
|
411
419
|
<h4>Important notes regarding the structure of <span class="caps">EC2</span>::Response Objects</h4>
|
|
412
420
|
|
|
@@ -419,59 +427,60 @@ benefit. What this means though, is that you may have to do a little homework o
|
|
|
419
427
|
For example, when you make a #describe_images call in ec2sh to <span class="caps">EC2</span> what you will get back will look like:</p>
|
|
420
428
|
|
|
421
429
|
|
|
422
|
-
<pre syntax
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
430
|
+
<p><pre class='syntax'>
|
|
431
|
+
<span class="global">$ </span><span class="ident">ec2sh</span>
|
|
432
|
+
<span class="punct">>></span> <span class="ident">puts</span> <span class="attribute">@ec2</span><span class="punct">.</span><span class="ident">describe_images</span><span class="punct">(</span><span class="symbol">:owner_id</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">amazon</span><span class="punct">').</span><span class="ident">xml</span>
|
|
433
|
+
|
|
434
|
+
<span class="punct"><</span><span class="char">?x</span><span class="ident">ml</span> <span class="ident">version</span><span class="punct">="</span><span class="string">1.0</span><span class="punct">"</span><span class="char">?></span>
|
|
435
|
+
<span class="punct"><</span><span class="constant">DescribeImagesResponse</span> <span class="ident">xmlns</span><span class="punct">="</span><span class="string">http://ec2.amazonaws.com/doc/2007-01-19/</span><span class="punct">"></span>
|
|
436
|
+
<span class="punct"><</span><span class="ident">imagesSet</span><span class="punct">></span>
|
|
437
|
+
<span class="punct"><</span><span class="ident">item</span><span class="punct">></span>
|
|
438
|
+
<span class="punct"><</span><span class="ident">imageId</span><span class="punct">></span><span class="ident">ami</span><span class="punct">-</span><span class="number">20</span><span class="ident">b65349</span><span class="punct"></</span><span class="regex">imageId>
|
|
439
|
+
<imageLocation>ec2-public-images</span><span class="punct">/</span><span class="ident">fedora</span><span class="punct">-</span><span class="ident">core4</span><span class="punct">-</span><span class="ident">base</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
440
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
441
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
442
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
443
|
+
<span class="punct"></</span><span class="regex">item>
|
|
429
444
|
<item>
|
|
430
|
-
<imageId>ami-
|
|
431
|
-
|
|
432
|
-
<imageState>available<
|
|
433
|
-
|
|
434
|
-
<isPublic>true<
|
|
435
|
-
|
|
445
|
+
<imageId>ami-22b6534b<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
|
446
|
+
<span class="punct"><</span><span class="ident">imageLocation</span><span class="punct">></span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">public</span><span class="punct">-</span><span class="ident">images</span><span class="punct">/</span><span class="ident">fedora</span><span class="punct">-</span><span class="ident">core4</span><span class="punct">-</span><span class="ident">mysql</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
447
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
448
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
449
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
450
|
+
<span class="punct"></</span><span class="regex">item>
|
|
436
451
|
<item>
|
|
437
|
-
<imageId>ami-
|
|
438
|
-
|
|
439
|
-
<imageState>available<
|
|
440
|
-
|
|
441
|
-
<isPublic>true<
|
|
442
|
-
|
|
452
|
+
<imageId>ami-23b6534a<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
|
453
|
+
<span class="punct"><</span><span class="ident">imageLocation</span><span class="punct">></span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">public</span><span class="punct">-</span><span class="ident">images</span><span class="punct">/</span><span class="ident">fedora</span><span class="punct">-</span><span class="ident">core4</span><span class="punct">-</span><span class="ident">apache</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
454
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
455
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
456
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
457
|
+
<span class="punct"></</span><span class="regex">item>
|
|
443
458
|
<item>
|
|
444
|
-
<imageId>ami-
|
|
445
|
-
|
|
446
|
-
<imageState>available<
|
|
447
|
-
|
|
448
|
-
<isPublic>true<
|
|
449
|
-
|
|
459
|
+
<imageId>ami-25b6534c<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
|
460
|
+
<span class="punct"><</span><span class="ident">imageLocation</span><span class="punct">></span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">public</span><span class="punct">-</span><span class="ident">images</span><span class="punct">/</span><span class="ident">fedora</span><span class="punct">-</span><span class="ident">core4</span><span class="punct">-</span><span class="ident">apache</span><span class="punct">-</span><span class="ident">mysql</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
461
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
462
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
463
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
464
|
+
<span class="punct"></</span><span class="regex">item>
|
|
450
465
|
<item>
|
|
451
|
-
<imageId>ami-
|
|
452
|
-
|
|
453
|
-
<imageState>available<
|
|
454
|
-
|
|
455
|
-
<isPublic>true<
|
|
456
|
-
|
|
466
|
+
<imageId>ami-26b6534f<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
|
467
|
+
<span class="punct"><</span><span class="ident">imageLocation</span><span class="punct">></span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">public</span><span class="punct">-</span><span class="ident">images</span><span class="punct">/</span><span class="ident">developer</span><span class="punct">-</span><span class="ident">image</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
468
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
469
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
470
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
471
|
+
<span class="punct"></</span><span class="regex">item>
|
|
457
472
|
<item>
|
|
458
|
-
<imageId>ami-
|
|
459
|
-
|
|
460
|
-
<imageState>available<
|
|
461
|
-
|
|
462
|
-
<isPublic>true<
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
<imageOwnerId>amazon</imageOwnerId>
|
|
469
|
-
<isPublic>true</isPublic>
|
|
470
|
-
</item>
|
|
471
|
-
</imagesSet>
|
|
472
|
-
</DescribeImagesResponse>
|
|
473
|
+
<imageId>ami-2bb65342<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
|
474
|
+
<span class="punct"><</span><span class="ident">imageLocation</span><span class="punct">></span><span class="ident">ec2</span><span class="punct">-</span><span class="ident">public</span><span class="punct">-</span><span class="ident">images</span><span class="punct">/</span><span class="ident">getting</span><span class="punct">-</span><span class="ident">started</span><span class="punct">.</span><span class="ident">manifest</span><span class="punct">.</span><span class="ident">xml</span><span class="punct"></</span><span class="regex">imageLocation>
|
|
475
|
+
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
|
476
|
+
<span class="punct"><</span><span class="ident">imageOwnerId</span><span class="punct">></span><span class="ident">amazon</span><span class="punct"></</span><span class="regex">imageOwnerId>
|
|
477
|
+
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
|
478
|
+
<span class="punct"></</span><span class="regex">item>
|
|
479
|
+
<</span><span class="punct">/</span><span class="ident">imagesSet</span><span class="punct">></span>
|
|
480
|
+
<span class="punct"></</span><span class="regex">DescribeImagesResponse>
|
|
481
|
+
<span class="normal">
|
|
482
|
+
</span></span></pre></p>
|
|
473
483
|
|
|
474
|
-
</pre>
|
|
475
484
|
|
|
476
485
|
<p>You can see in the <span class="caps">XML</span> the structure that you will need to follow when constructing queries for information and parsing responses from <span class="caps">EC2</span>.</p>
|
|
477
486
|
|
|
@@ -479,10 +488,11 @@ $ ec2sh
|
|
|
479
488
|
<p>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:</p>
|
|
480
489
|
|
|
481
490
|
|
|
482
|
-
<pre syntax
|
|
483
|
-
|
|
484
|
-
ami
|
|
485
|
-
</pre>
|
|
491
|
+
<p><pre class='syntax'>
|
|
492
|
+
<span class="punct">>></span> <span class="ident">puts</span> <span class="attribute">@ec2</span><span class="punct">.</span><span class="ident">describe_images</span><span class="punct">(</span><span class="symbol">:owner_id</span> <span class="punct">=></span> <span class="punct">'</span><span class="string">amazon</span><span class="punct">').</span><span class="ident">imagesSet</span><span class="punct">.</span><span class="ident">item</span><span class="punct">[</span><span class="number">2</span><span class="punct">].</span><span class="ident">imageId</span>
|
|
493
|
+
<span class="ident">ami</span><span class="punct">-</span><span class="number">23</span><span class="ident">b6534a</span>
|
|
494
|
+
</pre></p>
|
|
495
|
+
|
|
486
496
|
|
|
487
497
|
<p><span class="caps">EC2</span> 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 <span class="caps">EC2</span>::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 <span class="caps">EC2</span>::Response#xml method like I did above to see the exact <span class="caps">XML</span> returned which allows you to easily derive the structure for the Ruby OpenStruct object.</p>
|
|
488
498
|
|
|
@@ -543,7 +553,7 @@ ami-23b6534a
|
|
|
543
553
|
|
|
544
554
|
<p>Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.</p>
|
|
545
555
|
<p class="coda">
|
|
546
|
-
<a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>,
|
|
556
|
+
<a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>, 26th September 2007<br>
|
|
547
557
|
</p>
|
|
548
558
|
</div>
|
|
549
559
|
|