amazon-ec2 0.2.10 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → CHANGELOG} +7 -0
- data/{License.txt → LICENSE} +0 -0
- data/README.rdoc +322 -0
- data/Rakefile +30 -4
- data/bin/ec2-gem-example.rb +0 -3
- data/lib/EC2.rb +1 -8
- data/lib/EC2/instances.rb +3 -2
- metadata +20 -58
- data/Manifest.txt +0 -46
- data/README.txt +0 -154
- data/config/hoe.rb +0 -76
- data/config/requirements.rb +0 -17
- data/lib/EC2/version.rb +0 -18
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -74
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -27
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/test_EC2_version.rb +0 -44
- data/website/index.html +0 -566
- data/website/index.txt +0 -427
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.rhtml +0 -55
data/tasks/deployment.rake
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
desc 'Release the website and new gem version'
|
2
|
-
task :deploy => [:check_version, :website, :release] do
|
3
|
-
puts "Remember to create SVN tag:"
|
4
|
-
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
-
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
-
puts "Suggested comment:"
|
7
|
-
puts "Tagging release #{CHANGES}"
|
8
|
-
end
|
9
|
-
|
10
|
-
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
-
task :local_deploy => [:website_generate, :install_gem]
|
12
|
-
|
13
|
-
task :check_version do
|
14
|
-
unless ENV['VERSION']
|
15
|
-
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
-
exit
|
17
|
-
end
|
18
|
-
unless ENV['VERSION'] == VERS
|
19
|
-
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
-
task :install_gem_no_doc => [:clean, :package] do
|
26
|
-
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
-
end
|
data/tasks/environment.rake
DELETED
data/tasks/website.rake
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
desc 'Generate website files'
|
2
|
-
task :website_generate => :ruby_env do
|
3
|
-
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
-
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
desc 'Upload website files to rubyforge'
|
9
|
-
task :website_upload do
|
10
|
-
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
-
remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/"
|
12
|
-
local_dir = 'website'
|
13
|
-
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
-
end
|
15
|
-
|
16
|
-
desc 'Generate and upload website files'
|
17
|
-
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/test/test_EC2_version.rb
DELETED
@@ -1,44 +0,0 @@
|
|
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
|
data/website/index.html
DELETED
@@ -1,566 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
-
<title>
|
8
|
-
Amazon Web Services EC2 Ruby Gem
|
9
|
-
</title>
|
10
|
-
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
-
<style>
|
12
|
-
|
13
|
-
</style>
|
14
|
-
<script type="text/javascript">
|
15
|
-
window.onload = function() {
|
16
|
-
settings = {
|
17
|
-
tl: { radius: 10 },
|
18
|
-
tr: { radius: 10 },
|
19
|
-
bl: { radius: 10 },
|
20
|
-
br: { radius: 10 },
|
21
|
-
antiAlias: true,
|
22
|
-
autoPad: true,
|
23
|
-
validTags: ["div"]
|
24
|
-
}
|
25
|
-
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
-
versionBox.applyCornersToAll();
|
27
|
-
}
|
28
|
-
</script>
|
29
|
-
</head>
|
30
|
-
<body>
|
31
|
-
<div id="main">
|
32
|
-
|
33
|
-
<h1>Amazon Web Services EC2 Ruby Gem</h1>
|
34
|
-
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/amazon-ec2"; return false'>
|
35
|
-
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/amazon-ec2" class="numbers">0.2.10</a>
|
37
|
-
</div>
|
38
|
-
<h2>→ ‘amazon-ec2’</h2>
|
39
|
-
|
40
|
-
|
41
|
-
<h2>About</h2>
|
42
|
-
|
43
|
-
|
44
|
-
<p>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 <span class="caps">HTTP</span> Query <span class="caps">API</span> calls to <span class="caps">EC2</span>.</p>
|
45
|
-
|
46
|
-
|
47
|
-
<p>This ‘amazon-ec2’ Ruby Gem is an interface library that can be used to interact with the Amazon <span class="caps">EC2</span> system and control server resources on demand from your Ruby scripts, or from Ruby on Rails applications.</p>
|
48
|
-
|
49
|
-
|
50
|
-
<h2>What’s new?</h2>
|
51
|
-
|
52
|
-
|
53
|
-
<p>20080331 – Gem version 0.2.9 Updated with initial support of the new Amazon Web Services 2008-02-01 public <span class="caps">API</span>. So far support has been added for the new ‘Elastic IP’ functionality.</p>
|
54
|
-
|
55
|
-
|
56
|
-
<p>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 <a href="http://github.com/grempe/amazon-ec2">http://github.com/grempe/amazon-ec2</a>. Please let us know if you have patches you would like us to pull from your git repository.</p>
|
57
|
-
|
58
|
-
|
59
|
-
<p>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:</p>
|
60
|
-
|
61
|
-
|
62
|
-
<ul>
|
63
|
-
<li>Updated <span class="caps">API</span> version in the query <span class="caps">API</span> request to 2007-08-29, and added all known method calls
|
64
|
-
in this version of the <span class="caps">API</span> to the gem (including the new instance types(small, medium, large)).
|
65
|
-
Previous releases have kept pace with changes such as the addition of paid <span class="caps">AMI</span> support with
|
66
|
-
product codes, instance reboot, viewing of console output, <span class="caps">NAT</span> addressing and more!</li>
|
67
|
-
</ul>
|
68
|
-
|
69
|
-
|
70
|
-
<ul>
|
71
|
-
<li><span class="caps">MAJOR</span> library changes : <span class="caps">THESE CHANGES ARE NOT BACKWARD COMPATIBLE</span>!! You will need to update
|
72
|
-
the way in which you make calls, handle responses, and rescue exceptions from this library.
|
73
|
-
If you prefer not to make these changes you can feel free to continue to use the older version
|
74
|
-
of the gem. These older versions however will no longer be maintained.</li>
|
75
|
-
</ul>
|
76
|
-
|
77
|
-
|
78
|
-
<ul>
|
79
|
-
<li><span class="caps">MAJOR</span> refactoring of how methods calls are made. Now all methods are called with a simple hash
|
80
|
-
of arguments and none of them are positional. This feels much more “Ruby’ish”.</li>
|
81
|
-
</ul>
|
82
|
-
|
83
|
-
|
84
|
-
<ul>
|
85
|
-
<li><span class="caps">MAJOR</span> refactoring of how responses are returned to users. No longer do you have to call the
|
86
|
-
.parse method, and no longer are you getting back simple arrays of information. Responses
|
87
|
-
now come in the form of OpenStruct objects that contain all of the data for an object in
|
88
|
-
Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an <span class="caps">EC2</span>::Response object
|
89
|
-
which inherits from OpenStruct. The return data from <span class="caps">EC2</span>, which is in <span class="caps">XML</span> form, is parsed
|
90
|
-
with XmlSimple and is used to directly construct the return data structure. This allows us
|
91
|
-
to know with some confidence that the data structure returned from <span class="caps">AWS</span> will always be consistent
|
92
|
-
with this library’s responses. There is also an .xml attribute for each response object that lets you
|
93
|
-
see the full and complete <span class="caps">XML</span> response from <span class="caps">AWS</span> if that is useful to you.</li>
|
94
|
-
</ul>
|
95
|
-
|
96
|
-
|
97
|
-
<ul>
|
98
|
-
<li>Added an exception framework which will now throw appropriate Ruby exceptions
|
99
|
-
that match those handed to us by Amazon <span class="caps">EC2</span>. ArgumentError exceptions will also
|
100
|
-
be thrown if you are making calls we know to be illegal or malformed. You should rescue
|
101
|
-
these exceptions in your application instead of parsing text responses. All exceptions
|
102
|
-
descend from <span class="caps">EC2</span>::Error. You can see them all in exceptions.rb in the gem install.</li>
|
103
|
-
</ul>
|
104
|
-
|
105
|
-
|
106
|
-
<ul>
|
107
|
-
<li>Added a full suite of test/spec unit tests which currently cover 100% of the public methods
|
108
|
-
in this library. We have abot 92% code coverage according to rcov. This has greatly enhanced
|
109
|
-
the reliability of the library as well as our confidence in the code.
|
110
|
-
We used to have 0% test coverage. :-/</li>
|
111
|
-
</ul>
|
112
|
-
|
113
|
-
|
114
|
-
<ul>
|
115
|
-
<li>Added an <span class="caps">EC2</span> command shell : ‘ec2sh’ which can be called from anywhere and gives you
|
116
|
-
an interactive irb session with an <span class="caps">EC2</span> connection pre-made for you as @ec2. You can use this
|
117
|
-
to interactively execute any command on <span class="caps">EC2</span> that this library supports. Try @ec2.methods.sort
|
118
|
-
or @ec2.describe_images to test it out. You must first setup two shell environment variables
|
119
|
-
which contain your <span class="caps">ACCESS</span>_KEY_ID and <span class="caps">SECRET</span>_ACCESS_KEY for this to work. Otherwise an error
|
120
|
-
will be thrown when you try to start it. This is way cool and shamelessly borrowed from
|
121
|
-
Marcel Molina’s fine <span class="caps">AWS</span>::S3 library.</li>
|
122
|
-
</ul>
|
123
|
-
|
124
|
-
|
125
|
-
<ul>
|
126
|
-
<li>Removed .parse method as it is no longer needed or wanted.</li>
|
127
|
-
</ul>
|
128
|
-
|
129
|
-
|
130
|
-
<h2>Installing</h2>
|
131
|
-
|
132
|
-
|
133
|
-
<p>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.</p>
|
134
|
-
|
135
|
-
|
136
|
-
<h3>Installation pre-requisites</h3>
|
137
|
-
|
138
|
-
|
139
|
-
<h4><a href="https://aws-portal.amazon.com/gp/aws/developer/registration/index.html">Amazon Web Services developer account</a>.</h4>
|
140
|
-
|
141
|
-
|
142
|
-
<p>You’ll need an account with <span class="caps">AWS</span> 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 <span class="caps">EC2</span> usage. After signup you’ll be provided with an ‘Access Key ID’ and a ‘Secret Access Key’. These allow you to authenticate any <span class="caps">API</span> 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!).</p>
|
143
|
-
|
144
|
-
|
145
|
-
<h4>Gem Dependencies</h4>
|
146
|
-
|
147
|
-
|
148
|
-
<p>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.</p>
|
149
|
-
|
150
|
-
|
151
|
-
<p><a href="http://xml-simple.rubyforge.org/">XmlSimple</a> (required)</p>
|
152
|
-
|
153
|
-
|
154
|
-
<p><a href="http://mocha.rubyforge.org/">Mocha</a> (optional for testing)</p>
|
155
|
-
|
156
|
-
|
157
|
-
<p><a href="http://eigenclass.org/hiki.rb?rcov">Rcov</a> (optional for testing)</p>
|
158
|
-
|
159
|
-
|
160
|
-
<p><a href="http://test-spec.rubyforge.org/test-spec/">Test-Spec</a> (optional for testing)</p>
|
161
|
-
|
162
|
-
|
163
|
-
<p><a href="http://syntax.rubyforge.org/">Syntax</a> (optional for building your own copy of the gem and its docs)</p>
|
164
|
-
|
165
|
-
|
166
|
-
<p><a href="http://whytheluckystiff.net/ruby/redcloth">RedCloth</a> (optional for building your own copy of the gem and its docs)</p>
|
167
|
-
|
168
|
-
|
169
|
-
<h3>Installing the gem</h3>
|
170
|
-
|
171
|
-
|
172
|
-
<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>
|
173
|
-
|
174
|
-
|
175
|
-
<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>
|
176
|
-
|
177
|
-
|
178
|
-
<h2>Using the library</h2>
|
179
|
-
|
180
|
-
|
181
|
-
<h3>Setting up…</h3>
|
182
|
-
|
183
|
-
|
184
|
-
<p>The ‘ec2sh’ and ‘ec2-gem-example.rb’ scripts which will be introduced to you shortly expect your <span class="caps">AWS EC2</span> credentials to
|
185
|
-
be stored as shell environment variables which are accessible to those scripts. This makes them convenient to use whenever
|
186
|
-
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
|
187
|
-
instance on <span class="caps">EC2</span>. You’ll find ‘ec2sh’ to be a very handy tool. I’ll describe only the <span class="caps">OS X</span> route for setting up (of course
|
188
|
-
the setup steps will vary depending on your particular system and preferred shell). If you don’t want to
|
189
|
-
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.</p>
|
190
|
-
|
191
|
-
|
192
|
-
<h4><span class="caps">OS X</span> Setup</h4>
|
193
|
-
|
194
|
-
|
195
|
-
<p>Edit the file ~/.bash_login and add the following to the existing contents:</p>
|
196
|
-
|
197
|
-
|
198
|
-
<p><pre class='syntax'>
|
199
|
-
|
200
|
-
<span class="ident">export</span> <span class="constant">RUBYOPT</span><span class="punct">="</span><span class="string">rubygems</span><span class="punct">"</span>
|
201
|
-
|
202
|
-
<span class="comment"># For amazon-ec2 and amazon s3 ruby gems</span>
|
203
|
-
<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>
|
204
|
-
<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>
|
205
|
-
|
206
|
-
</pre></p>
|
207
|
-
|
208
|
-
|
209
|
-
<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>
|
210
|
-
|
211
|
-
|
212
|
-
<p>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.</p>
|
213
|
-
|
214
|
-
|
215
|
-
<h3>The basics…</h3>
|
216
|
-
|
217
|
-
|
218
|
-
<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>
|
219
|
-
|
220
|
-
|
221
|
-
<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
|
222
|
-
method calls directly against <span class="caps">EC2</span>. All the operations for using the <span class="caps">EC2</span> service, including query string header signing,
|
223
|
-
are handled automatically for you. The connection string will look something like this:</p>
|
224
|
-
|
225
|
-
|
226
|
-
<p><pre class='syntax'>
|
227
|
-
<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>
|
228
|
-
</pre></p>
|
229
|
-
|
230
|
-
|
231
|
-
<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>.
|
232
|
-
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.
|
233
|
-
In most cases the methods names only differ in how they are presented. e.g. ‘DescribeImages’ becomes ’#describe_images() in Ruby.
|
234
|
-
Feel free to browse the full <a href="http://amazon-ec2.rubyforge.org/rdoc/">RDoc documentation</a> for all classes and methods of ‘amazon-ec2’ if you want more details.</p>
|
235
|
-
|
236
|
-
|
237
|
-
<h3>Examples</h3>
|
238
|
-
|
239
|
-
|
240
|
-
<p>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.</p>
|
241
|
-
|
242
|
-
|
243
|
-
<h4>Using the ‘ec2-gem-example.rb’ sample test script</h4>
|
244
|
-
|
245
|
-
|
246
|
-
<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>
|
247
|
-
|
248
|
-
|
249
|
-
<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>
|
250
|
-
|
251
|
-
|
252
|
-
<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>
|
253
|
-
|
254
|
-
|
255
|
-
<h4>Using the ‘ec2sh’ command shell</h4>
|
256
|
-
|
257
|
-
|
258
|
-
<p>The ‘ec2sh’ command shell is actually a standard ‘irb’ Ruby shell, with the main difference being we read your <span class="caps">AWS</span> credentials from your environment and pre-configure a connection string for you. This lets you run any <span class="caps">EC2</span> 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…</p>
|
259
|
-
|
260
|
-
|
261
|
-
<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>
|
262
|
-
|
263
|
-
|
264
|
-
<p><pre class='syntax'>
|
265
|
-
|
266
|
-
<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>
|
267
|
-
|
268
|
-
<span class="punct">'</span><span class="string">ec2sh</span><span class="punct">'</span> <span class="ident">usage</span> <span class="punct">:</span>
|
269
|
-
<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>
|
270
|
-
<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
|
271
|
-
great tool to help you debug issues and practice running commands
|
272
|
-
against the live EC2 servers prior to putting them in your code.
|
273
|
-
|
274
|
-
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
|
275
|
-
on this to execute commands on EC2. Adding a #to_s
|
276
|
-
at the end of any command should give you a full String representation of the
|
277
|
-
response. The #xml data is available for each response
|
278
|
-
which allows you to view the full and complete XML response returned by
|
279
|
-
EC2 without any parsing applied. This is useful for viewing the
|
280
|
-
hierarchy of an entire response in a friendly way (if XML is friendly
|
281
|
-
to you!). Understanding the hierarchy of the XML response is critical
|
282
|
-
to making effective use of this library.
|
283
|
-
|
284
|
-
Examples to try:
|
285
|
-
|
286
|
-
returns : all ec2 public methods
|
287
|
-
>> @ec2.methods.sort
|
288
|
-
|
289
|
-
returns : a string representation of ALL images
|
290
|
-
>> @ec2.describe_images.to_s
|
291
|
-
|
292
|
-
returns : an Array of EC2::Response objects, each an EC2 image and its data
|
293
|
-
>> @ec2.describe_images.imagesSet.item
|
294
|
-
>> @ec2.describe_images.imagesSet.item[0] (an OpenStruct of a single item in that array)
|
295
|
-
>> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that OpenStruct item)
|
296
|
-
|
297
|
-
returns : an XML representation of all images
|
298
|
-
>> puts @ec2.describe_images.xml
|
299
|
-
|
300
|
-
returns : an XML representation of all images owned by Amazon
|
301
|
-
>> puts @ec2.describe_images(:owner_id => </span><span class="punct">'</span><span class="ident">amazon</span><span class="punct">'</span><span class="string">).xml
|
302
|
-
|
303
|
-
>> @ec2.describe_images.imagesSet.item[0].to_s
|
304
|
-
=> "#<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 ...>>"
|
305
|
-
<span class="normal">
|
306
|
-
</span></span></pre></p>
|
307
|
-
|
308
|
-
|
309
|
-
<h4>Using ‘amazon-ec2’ in Ruby scripts</h4>
|
310
|
-
|
311
|
-
|
312
|
-
<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>
|
313
|
-
|
314
|
-
|
315
|
-
<p><pre class='syntax'>
|
316
|
-
<span class="comment">#!/usr/bin/env ruby</span>
|
317
|
-
|
318
|
-
<span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
|
319
|
-
<span class="ident">require</span> <span class="punct">'</span><span class="string">ec2</span><span class="punct">'</span>
|
320
|
-
|
321
|
-
<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>
|
322
|
-
<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>
|
323
|
-
|
324
|
-
<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>
|
325
|
-
|
326
|
-
<span class="ident">puts</span> <span class="punct">"</span><span class="string">----- listing images owned by 'amazon' -----</span><span class="punct">"</span>
|
327
|
-
<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>
|
328
|
-
<span class="comment"># OpenStruct objects have members!</span>
|
329
|
-
<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>
|
330
|
-
<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>
|
331
|
-
<span class="keyword">end</span>
|
332
|
-
<span class="keyword">end</span>
|
333
|
-
</pre></p>
|
334
|
-
|
335
|
-
|
336
|
-
<h4>Using ‘amazon-ec2’ in Ruby on Rails applications</h4>
|
337
|
-
|
338
|
-
|
339
|
-
<p>in config/environment.rb:</p>
|
340
|
-
|
341
|
-
|
342
|
-
<p><pre class='syntax'>
|
343
|
-
<span class="comment"># Require the amazon-ec2 gem and make its methods available in your Rails app</span>
|
344
|
-
<span class="comment"># Put this at the bottom of your environment.rb</span>
|
345
|
-
<span class="ident">require</span> <span class="punct">'</span><span class="string">EC2</span><span class="punct">'</span>
|
346
|
-
</pre></p>
|
347
|
-
|
348
|
-
|
349
|
-
<p>in app/controllers/your_controller.rb:
|
350
|
-
<pre class='syntax'>
|
351
|
-
|
352
|
-
<span class="punct">[</span><span class="ident">some</span> <span class="ident">controller</span> <span class="ident">code</span> <span class="punct">...]</span>
|
353
|
-
|
354
|
-
<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>
|
355
|
-
|
356
|
-
<span class="comment"># get ALL public images</span>
|
357
|
-
<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>
|
358
|
-
|
359
|
-
<span class="comment"># Get info on all public EC2 images created by the Amazon EC2 team.</span>
|
360
|
-
<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>
|
361
|
-
|
362
|
-
<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>
|
363
|
-
|
364
|
-
</pre></p>
|
365
|
-
|
366
|
-
|
367
|
-
<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>
|
368
|
-
|
369
|
-
|
370
|
-
<p><pre class='syntax'>
|
371
|
-
|
372
|
-
<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>
|
373
|
-
|
374
|
-
<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>
|
375
|
-
|
376
|
-
<%= debug(@ec2_images_amazon) %>
|
377
|
-
|
378
|
-
<h1>Sample 2 - Build a table<</span><span class="punct">/</span><span class="ident">h1</span><span class="punct">></span>
|
379
|
-
|
380
|
-
<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>
|
381
|
-
<span class="punct"><</span><span class="ident">tr</span><span class="punct">></span>
|
382
|
-
<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>
|
383
|
-
<th>image.imageLocation<</span><span class="punct">/</span><span class="ident">th</span><span class="punct">></span>
|
384
|
-
<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>
|
385
|
-
<th>image.imageState<</span><span class="punct">/</span><span class="ident">th</span><span class="punct">></span>
|
386
|
-
<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>
|
387
|
-
<</span><span class="punct">/</span><span class="ident">tr</span><span class="punct">></span>
|
388
|
-
|
389
|
-
<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">
|
390
|
-
<tr</span><span class="punct">></span>
|
391
|
-
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.imageId %></td>
|
392
|
-
<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>
|
393
|
-
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.imageOwnerId %></td>
|
394
|
-
<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>
|
395
|
-
<span class="punct"><</span><span class="ident">td</span><span class="punct">><%=</span><span class="string">h image.isPublic %></td>
|
396
|
-
</tr>
|
397
|
-
<% end %>
|
398
|
-
</table>
|
399
|
-
|
400
|
-
<h1>Sample 3 - Iterate</h1>
|
401
|
-
|
402
|
-
<% @ec2_images_amazon.each do |image| %>
|
403
|
-
<% image.each_pair do |key, value| %>
|
404
|
-
<% 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">
|
405
|
-
<%= "<span class="expr">#{key}</span> =</span><span class="punct">></span> <span class="comment">#{value}" %><br /></span>
|
406
|
-
<span class="punct"><%</span> <span class="keyword">end</span> <span class="punct">%></span><span class="string">
|
407
|
-
<% end %</span><span class="punct">></span>
|
408
|
-
<span class="punct"><</span><span class="ident">br</span> <span class="punct">/></span>
|
409
|
-
<span class="punct"><%</span> <span class="keyword">end</span> <span class="punct">%></span><span class="string">
|
410
|
-
<span class="normal">
|
411
|
-
</span></span></pre></p>
|
412
|
-
|
413
|
-
|
414
|
-
<h4>Important notes regarding the structure of <span class="caps">EC2</span>::Response Objects</h4>
|
415
|
-
|
416
|
-
|
417
|
-
<p>One of the key benefits of this new version of the library is that all responses from <span class="caps">EC2</span> are bundled up in
|
418
|
-
a real data structure and no longer require parsing of text. We use an OpenStruct as the parent for the <span class="caps">EC2</span>::Response
|
419
|
-
object and we populate it directly from the <span class="caps">XML</span> given to us by <span class="caps">EC2</span> in response to any command we issue. This means that
|
420
|
-
future changes to the <span class="caps">API</span> and what is returned by <span class="caps">EC2</span> will largely be handled transparently by the gem. This is a huge
|
421
|
-
benefit. What this means though, is that you may have to do a little homework on what actually gets returned by <span class="caps">EC2</span> as <span class="caps">XML</span>.
|
422
|
-
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>
|
423
|
-
|
424
|
-
|
425
|
-
<p><pre class='syntax'>
|
426
|
-
<span class="global">$ </span><span class="ident">ec2sh</span>
|
427
|
-
<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>
|
428
|
-
|
429
|
-
<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>
|
430
|
-
<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>
|
431
|
-
<span class="punct"><</span><span class="ident">imagesSet</span><span class="punct">></span>
|
432
|
-
<span class="punct"><</span><span class="ident">item</span><span class="punct">></span>
|
433
|
-
<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>
|
434
|
-
<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>
|
435
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
436
|
-
<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>
|
437
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
438
|
-
<span class="punct"></</span><span class="regex">item>
|
439
|
-
<item>
|
440
|
-
<imageId>ami-22b6534b<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
441
|
-
<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>
|
442
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
443
|
-
<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>
|
444
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
445
|
-
<span class="punct"></</span><span class="regex">item>
|
446
|
-
<item>
|
447
|
-
<imageId>ami-23b6534a<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
448
|
-
<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>
|
449
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
450
|
-
<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>
|
451
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
452
|
-
<span class="punct"></</span><span class="regex">item>
|
453
|
-
<item>
|
454
|
-
<imageId>ami-25b6534c<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
455
|
-
<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>
|
456
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
457
|
-
<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>
|
458
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
459
|
-
<span class="punct"></</span><span class="regex">item>
|
460
|
-
<item>
|
461
|
-
<imageId>ami-26b6534f<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
462
|
-
<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>
|
463
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
464
|
-
<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>
|
465
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
466
|
-
<span class="punct"></</span><span class="regex">item>
|
467
|
-
<item>
|
468
|
-
<imageId>ami-2bb65342<</span><span class="punct">/</span><span class="ident">imageId</span><span class="punct">></span>
|
469
|
-
<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>
|
470
|
-
<imageState>available<</span><span class="punct">/</span><span class="ident">imageState</span><span class="punct">></span>
|
471
|
-
<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>
|
472
|
-
<isPublic>true<</span><span class="punct">/</span><span class="ident">isPublic</span><span class="punct">></span>
|
473
|
-
<span class="punct"></</span><span class="regex">item>
|
474
|
-
<</span><span class="punct">/</span><span class="ident">imagesSet</span><span class="punct">></span>
|
475
|
-
<span class="punct"></</span><span class="regex">DescribeImagesResponse>
|
476
|
-
<span class="normal">
|
477
|
-
</span></span></pre></p>
|
478
|
-
|
479
|
-
|
480
|
-
<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>
|
481
|
-
|
482
|
-
|
483
|
-
<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>
|
484
|
-
|
485
|
-
|
486
|
-
<p><pre class='syntax'>
|
487
|
-
<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>
|
488
|
-
<span class="ident">ami</span><span class="punct">-</span><span class="number">23</span><span class="ident">b6534a</span>
|
489
|
-
</pre></p>
|
490
|
-
|
491
|
-
|
492
|
-
<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>
|
493
|
-
|
494
|
-
|
495
|
-
<h2>Contributing</h2>
|
496
|
-
|
497
|
-
|
498
|
-
<p>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.</p>
|
499
|
-
|
500
|
-
|
501
|
-
<h2>Project Info</h2>
|
502
|
-
|
503
|
-
|
504
|
-
<p>This project is managed as a RubyForge project which you can find at <a href="http://amazon-ec2.rubyforge.org/">http://amazon-ec2.rubyforge.org/</a> 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 : <a href="http://github.com/grempe/amazon-ec2">http://github.com/grempe/amazon-ec2</a>.</p>
|
505
|
-
|
506
|
-
|
507
|
-
<h2>Learning More</h2>
|
508
|
-
|
509
|
-
|
510
|
-
<h3>Documentation</h3>
|
511
|
-
|
512
|
-
|
513
|
-
<p>Complete RDoc generated documentation can be found at <a href="http://amazon-ec2.rubyforge.org/rdoc/">http://amazon-ec2.rubyforge.org/rdoc/</a></p>
|
514
|
-
|
515
|
-
|
516
|
-
<h3>Websites</h3>
|
517
|
-
|
518
|
-
|
519
|
-
<p><a href="http://aws.amazon.com/">Amazon Web Services Home</a>
|
520
|
-
<a href="http://rubyforge.org/projects/amazon-ec2/">Project Home</a>
|
521
|
-
<a href="http://rubyforge.org/frs/?group_id=2753">Downloads</a>
|
522
|
-
<a href="http://github.com/grempe/amazon-ec2">Browse Code</a>
|
523
|
-
<a href="http://rubyforge.org/tracker/?group_id=2753">Report Bugs</a>
|
524
|
-
<a href="http://rubyforge.org/tracker/?group_id=2753">Request Features</a>
|
525
|
-
<a href="http://rubyforge.org/tracker/?group_id=2753">Submit Patches</a></p>
|
526
|
-
|
527
|
-
|
528
|
-
<h3>Related Projects</h3>
|
529
|
-
|
530
|
-
|
531
|
-
<p><a href="http://capsize.rubyforge.org/">Capsize</a> : A Capistrano (>= 2.x) plugin that allows complete control of Amazon <span class="caps">EC2</span> from Capistrano recipes.</p>
|
532
|
-
|
533
|
-
|
534
|
-
<h2>Credits</h2>
|
535
|
-
|
536
|
-
|
537
|
-
<p>The original sample code for this library was provided by Amazon Web Services, <span class="caps">LLC</span>. 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 <span class="caps">EC2</span> team for including Ruby in their plans. We hope to see more <span class="caps">AWS</span> Ruby code.</p>
|
538
|
-
|
539
|
-
|
540
|
-
<p>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.</p>
|
541
|
-
|
542
|
-
|
543
|
-
<p>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 <a href="http://newgem.rubyforge.org/">http://newgem.rubyforge.org/</a></p>
|
544
|
-
|
545
|
-
|
546
|
-
<h2>Contact</h2>
|
547
|
-
|
548
|
-
|
549
|
-
<p>Comments, patches, and bug reports are welcome. Send an email to the address below or use the RubyForge forum for this project.</p>
|
550
|
-
<p class="coda">
|
551
|
-
<a href="mailto:grempe-at-rubyforge-dot-org">Glenn Rempe</a>, 31st March 2008<br>
|
552
|
-
</p>
|
553
|
-
</div>
|
554
|
-
|
555
|
-
<!-- insert site tracking codes here, like Google Urchin -->
|
556
|
-
|
557
|
-
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
558
|
-
|
559
|
-
</script>
|
560
|
-
<script type="text/javascript">
|
561
|
-
_uacct = "UA-312156-11";
|
562
|
-
urchinTracker();
|
563
|
-
</script>
|
564
|
-
|
565
|
-
</body>
|
566
|
-
</html>
|