Module: EC2

Defined in:
lib/EC2/images.rb,
lib/EC2.rb,
lib/EC2/console.rb,
lib/EC2/volumes.rb,
lib/EC2/keypairs.rb,
lib/EC2/products.rb,
lib/EC2/instances.rb,
lib/EC2/responses.rb,
lib/EC2/snapshots.rb,
lib/EC2/exceptions.rb,
lib/EC2/elastic_ips.rb,
lib/EC2/security_groups.rb,
lib/EC2/image_attributes.rb,
lib/EC2/availability_zones.rb

Overview

– Amazon Web Services EC2 Query API Ruby library

Ruby Gem Name

amazon-ec2

Author

Glenn Rempe ([email protected])

Copyright

Copyright © 2007-2008 Glenn Rempe

License

Distributes under the same terms as Ruby

Home

amazon-ec2.rubyforge.org

++

Defined Under Namespace

Classes: ArgumentError, AuthFailure, Base, Error, InstanceLimitExceeded, InsufficientInstanceCapacity, InternalError, InvalidAMIAttributeItemValue, InvalidAMIIDMalformed, InvalidAMIIDNotFound, InvalidAMIIDUnavailable, InvalidGroupDuplicate, InvalidGroupInUse, InvalidGroupNotFound, InvalidGroupReserved, InvalidInstanceIDMalformed, InvalidInstanceIDNotFound, InvalidKeyPairDuplicate, InvalidKeyPairNotFound, InvalidManifest, InvalidParameterCombination, InvalidPermissionDuplicate, InvalidPermissionMalformed, InvalidReservationIDMalformed, InvalidReservationIDNotFound, InvalidUserIDMalformed, Response, Unavailable, UnknownParameter

Constant Summary collapse

DEFAULT_HOST =

Which host FQDN will we connect to for all API calls to AWS?

'ec2.amazonaws.com'
API_VERSION =

This is the version of the API as defined by Amazon Web Services

'2008-05-05'

Class Method Summary collapse

Class Method Details

.canonical_string(path) ⇒ Object

Builds the canonical string for signing. This strips out all ‘&’, ‘?’, and ‘=’ from the query string to be signed.

Note:  The parameters in the path passed in must already be sorted in
case-insensitive alphabetical order and must not be url encoded.


31
32
33
34
35
36
37
# File 'lib/EC2.rb', line 31

def EC2.canonical_string(path)
  buf = ""
  path.split('&').each { |field|
    buf << field.gsub(/\&|\?/,"").sub(/=/,"")
  }
  return buf
end

.encode(secret_access_key, str, urlencode = true) ⇒ Object

Encodes the given string with the secret_access_key, by taking the hmac-sha1 sum, and then base64 encoding it. Optionally, it will also url encode the result of that to protect the string if it’s going to be used as a query string parameter.



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/EC2.rb', line 43

def EC2.encode(secret_access_key, str, urlencode=true)
  digest = OpenSSL::Digest::Digest.new('sha1')
  b64_hmac =
    Base64.encode64(
      OpenSSL::HMAC.digest(digest, secret_access_key, str)).strip

  if urlencode
    return CGI::escape(b64_hmac)
  else
    return b64_hmac
  end
end