public
Description: A Ruby Gem that gives you full access to several of the Amazon Web Services API from your Ruby/Ruby on Rails apps
Homepage: http://amazon-ec2.rubyforge.org/
Clone URL: git://github.com/grempe/amazon-ec2.git
Click here to lend your support to: amazon-ec2 and make a donation at www.pledgie.com !
grempe (author)
Sat Jun 13 11:16:56 -0700 2009
commit  97796041091a7ef43fdaffa2e36e71354b9437a3
tree    ef2e6460d65fb844a70aacee080656e308a65eb3
parent  bf7b7a80c370a7ee37a489f678b28b2534fad89b
amazon-ec2 / bin / ec2sh
100755 62 lines (47 sloc) 2.237 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
 
# Amazon Web Services EC2 Query API Ruby library
#
# Ruby Gem Name:: amazon-ec2
# Author:: Glenn Rempe (mailto:glenn@rempe.us)
# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
# License:: Distributes under the same terms as Ruby
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++
 
# CREDITS : Credit for this bit of shameful ripoff coolness
# goes to Marcel Molina and his AWS::S3 gem. Thanks!
 
# Usage : running this starts up an irb session and
# sets up the connection to EC2 as a class variable called
# '@ec2'. So just do something like the following on the
# shell command line:
 
# macbook-pro:~ glenn$ ec2sh
# >> @ec2.describe_images
# => [#<EC2::Item image_location...
 
ec2_lib = File.dirname(__FILE__) + '/../lib/EC2'
setup = File.dirname(__FILE__) + '/setup'
irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
 
if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
 
  welcome_message = <<-MESSAGE
 
'ec2sh' usage :
This is an interactive 'irb' command shell that allows you to use all
commands available to the amazon-ec2 gem. You'll find this to be a
great tool to help you debug issues and practice running commands
against the live EC2 servers prior to putting them in your code.
 
The EC2 connection is wired to the class instance '@ec2'. Make method calls
on this to execute commands on EC2. Adding a #to_s
at the end of any command should give you a full String representation of the
response.
 
Examples to try:
 
returns : all ec2 public methods
>> @ec2.methods.sort
 
returns : a string representation of ALL images
>> @ec2.describe_images.to_s
 
returns : an Array of EC2::Response objects, each an EC2 image and its data
>> @ec2.describe_images.imagesSet.item
>> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
>> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
 
MESSAGE
 
  puts welcome_message
  exec "#{irb_name} -r #{ec2_lib} -r #{setup} --simple-prompt"
else
  puts "You must define AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!"
end