Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

Commit

Permalink
Changed the env variable naming, IRB, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgonyea authored and grempe committed Mar 6, 2011
1 parent 640c8a4 commit 6b0b723
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 63 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Expand Up @@ -65,8 +65,8 @@ Edit the file ~/.bash_login and add the following to the existing contents:
export RUBYOPT="rubygems" export RUBYOPT="rubygems"


# For amazon-ec2 and amazon s3 ruby gems # For amazon-ec2 and amazon s3 ruby gems
export AMAZON_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID" export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
export AMAZON_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID" export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY_ID"


If you are using EC2 in the EU region, make sure you also set: If you are using EC2 in the EU region, make sure you also set:


Expand Down
98 changes: 51 additions & 47 deletions bin/awshell
@@ -1,5 +1,8 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby


require 'rubygems' if RUBY_VERSION < '1.9'
require 'irb'

# Amazon Web Services EC2 Query API Ruby library # Amazon Web Services EC2 Query API Ruby library
# #
# Ruby Gem Name:: amazon-ec2 # Ruby Gem Name:: amazon-ec2
Expand All @@ -12,70 +15,71 @@
# CREDITS : Credit for this bit of shameful ripoff coolness # CREDITS : Credit for this bit of shameful ripoff coolness
# goes to Marcel Molina and his AWS::S3 gem. Thanks! # goes to Marcel Molina and his AWS::S3 gem. Thanks!


aws_lib = File.dirname(__FILE__) + '/../lib/AWS' require File.dirname(__FILE__) + '/../lib/AWS'
setup = File.dirname(__FILE__) + '/setup'
irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'


welcome_message = <<-MESSAGE setup = File.dirname(__FILE__) + '/setup'


Usage : def welcome!
puts <<-MESSAGE
This is an interactive Ruby 'irb' shell that allows you to use the Usage :
AWS commands available in the 'amazon-ec2' gem. This can be a
great tool to help you debug issues and run commands
against the live AWS servers. You can do anything in this
shell that you can in a normal irb shell.
Config : This is an interactive Ruby 'irb' shell that allows you to use the
AWS commands available in the 'amazon-ec2' gem. This can be a
great tool to help you debug issues and run commands
against the live AWS servers. You can do anything in this
shell that you can in a normal irb shell.
You must set the following environment variables that contain your Config :
AWS credentials in your system shell for this to work.
AMAZON_ACCESS_KEY_ID You must set the following environment variables that contain your
AMAZON_SECRET_ACCESS_KEY AWS credentials in your system shell for this to work.
Each AWS service has its own default server endpoints. You can override AWS_ACCESS_KEY_ID
the endpoints with the following environment variables set in your AWS_SECRET_ACCESS_KEY
system shell:
EC2 : EC2_URL Each AWS service has its own default server endpoints. You can override
Elastic Load Balancing : ELB_URL the endpoints with the following environment variables set in your
AutoScaling : AS_URL system shell:
RDS : RDS_URL
CloudWatch : AWS_CLOUDWATCH_URL
For your convenience, the various AWS services are wired up in this shell EC2 : EC2_URL
to the following class variables. You can execute methods on each of these: Elastic Load Balancing : ELB_URL
AutoScaling : AS_URL
RDS : RDS_URL
CloudWatch : AWS_CLOUDWATCH_URL
@ec2 (Elastic Compute Cloud) For your convenience, the various AWS services are wired up in this shell
@elb (Elastic Load Balancing) to the following class variables. You can execute methods on each of these:
@as (AutoScaling)
@rds (Relational Database Service)
@cw (CloudWatch)
You can make method calls on these instances to execute commands against @ec2 (Elastic Compute Cloud)
the various services. Pre-pending a 'pp' should give you a pretty printed @elb (Elastic Load Balancing)
version of the response which may be easier to read. @as (AutoScaling)
@rds (Relational Database Service)
@cw (CloudWatch)
Examples: You can make method calls on these instances to execute commands against
the various services. Pre-pending a 'pp' should give you a pretty printed
version of the response which may be easier to read.
returns : Pretty Print all ec2 public methods Examples:
>> pp @ec2.methods.sort
returns : Pretty Print a Hash describing your EC2 images returns : Pretty Print all ec2 public methods
>> @ec2.describe_images(:owner_id => ['self']) >> pp @ec2.methods.sort
returns : an Array of AWS::Response objects, each an EC2 image and its data returns : Pretty Print a Hash describing your EC2 images
>> @ec2.describe_images(:owner_id => ['self']).imagesSet.item >> @ec2.describe_images(:owner_id => ['self'])
>> @ec2.describe_images(:owner_id => ['self']).imagesSet.item[0]
returns : an Array of AWS::Response objects, each an EC2 image and its data
>> @ec2.describe_images(:owner_id => ['self']).imagesSet.item
>> @ec2.describe_images(:owner_id => ['self']).imagesSet.item[0]
MESSAGE MESSAGE
end


if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] ) if((ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']) || (ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY']))
puts welcome_message puts "Please type 'welcome!' for an introduction on amazon-ec2"
exec "#{irb_name} -rubygems -r #{aws_lib} -r #{setup} --simple-prompt" IRB.start
require setup
else else
puts "You must define AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!" puts "You must define AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!"
puts welcome_message puts welcome!
end end

10 changes: 5 additions & 5 deletions bin/ec2-gem-example.rb
Expand Up @@ -18,14 +18,14 @@
# e.g. in ~/.bash_login # e.g. in ~/.bash_login
# #
# # For amazon-ec2 and amazon s3 ruby gems # # For amazon-ec2 and amazon s3 ruby gems
# export AMAZON_ACCESS_KEY_ID="FOO" # export AWS_SECRET_ACCESS_KEY="FOO"
# export AMAZON_SECRET_ACCESS_KEY="BAR" # export AWS_SECRET_ACCESS_KEY="BAR"


ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID'] ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID']
SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY'] SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']


if ACCESS_KEY_ID.nil? || ACCESS_KEY_ID.empty? if ACCESS_KEY_ID.nil? || ACCESS_KEY_ID.empty?
puts "Error : You must add the shell environment variables AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY before calling #{$0}!" puts "Error : You must add the shell environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY before calling #{$0}!"
exit exit
end end


Expand Down
7 changes: 4 additions & 3 deletions bin/ec2-gem-profile.rb
Expand Up @@ -3,8 +3,9 @@
# Basic single command application that we can call with perftools.rb to get consistent results. # Basic single command application that we can call with perftools.rb to get consistent results.


require File.dirname(__FILE__) + '/../lib/AWS' require File.dirname(__FILE__) + '/../lib/AWS'
ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID'] ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID']
SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY'] SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']

ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY ) ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
@images = ec2.describe_images


@images = ec2.describe_images
8 changes: 5 additions & 3 deletions bin/setup.rb
Expand Up @@ -9,11 +9,13 @@
# Home:: http://github.com/grempe/amazon-ec2/tree/master # Home:: http://github.com/grempe/amazon-ec2/tree/master
#++ #++


if ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY']

if(AWS::ACCESS_KEY_ID and AWS::SECRET_ACCESS_KEY)


opts = { opts = {
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], :access_key_id => AWS::ACCESS_KEY_ID,
:secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY'] :secret_access_key => AWS::SECRET_ACCESS_KEY
} }


if ENV['EC2_URL'] if ENV['EC2_URL']
Expand Down
7 changes: 4 additions & 3 deletions lib/AWS.rb
Expand Up @@ -50,6 +50,8 @@ def does_not_have?(key)




module AWS module AWS
ACCESS_KEY_ID = ENV['AWS_ACCESS_KEY_ID'] || ENV['AMAZON_ACCESS_KEY_ID'] || ""
SECRET_ACCESS_KEY = ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY'] || ""


# Builds the canonical string for signing requests. This strips out all '&', '?', and '=' # Builds the canonical string for signing requests. This strips out all '&', '?', and '='
# from the query string to be signed. The parameters in the path passed in must already # from the query string to be signed. The parameters in the path passed in must already
Expand Down Expand Up @@ -111,7 +113,6 @@ def AWS.encode(secret_access_key, str, urlencode=true)
# interface. You should not instantiate this directly, instead # interface. You should not instantiate this directly, instead
# you should setup an instance of 'AWS::EC2::Base' or 'AWS::ELB::Base'. # you should setup an instance of 'AWS::EC2::Base' or 'AWS::ELB::Base'.
class Base class Base

attr_reader :use_ssl, :server, :proxy_server, :port attr_reader :use_ssl, :server, :proxy_server, :port


# @option options [String] :access_key_id ("") The user's AWS Access Key ID # @option options [String] :access_key_id ("") The user's AWS Access Key ID
Expand All @@ -122,8 +123,8 @@ class Base
# @return [Object] the object. # @return [Object] the object.
def initialize( options = {} ) def initialize( options = {} )


options = { :access_key_id => "", options = { :access_key_id => ACCESS_KEY_ID,
:secret_access_key => "", :secret_access_key => SECRET_ACCESS_KEY,
:use_ssl => true, :use_ssl => true,
:server => default_host, :server => default_host,
:path => "/", :path => "/",
Expand Down

0 comments on commit 6b0b723

Please sign in to comment.