Module: AWS

Defined in:
lib/AWS/exceptions.rb,
lib/AWS.rb,
lib/AWS/EC2.rb,
lib/AWS/RDS.rb,
lib/AWS/ELB.rb,
lib/AWS/RDS/rds.rb,
lib/AWS/version.rb,
lib/AWS/EC2/tags.rb,
lib/AWS/responses.rb,
lib/AWS/Cloudwatch.rb,
lib/AWS/EC2/images.rb,
lib/AWS/EC2/devpay.rb,
lib/AWS/EC2/volumes.rb,
lib/AWS/EC2/console.rb,
lib/AWS/Autoscaling.rb,
lib/AWS/EC2/subnets.rb,
lib/AWS/EC2/keypairs.rb,
lib/AWS/EC2/products.rb,
lib/AWS/EC2/password.rb,
lib/AWS/EC2/snapshots.rb,
lib/AWS/EC2/instances.rb,
lib/AWS/EC2/elastic_ips.rb,
lib/AWS/EC2/spot_prices.rb,
lib/AWS/ELB/load_balancers.rb,
lib/AWS/EC2/security_groups.rb,
lib/AWS/EC2/image_attributes.rb,
lib/AWS/Cloudwatch/monitoring.rb,
lib/AWS/EC2/availability_zones.rb,
lib/AWS/Autoscaling/autoscaling.rb,
lib/AWS/EC2/spot_instance_requests.rb

Overview

– AWS ERROR CODES AWS can throw error exceptions that contain a '.' in them. since we can't name an exception class with that '.' I compressed each class name into the non-dot version which allows us to retain the granularity of the exception. ++

Defined Under Namespace

Modules: Autoscaling, Cloudwatch, EC2, ELB, RDS Classes: AddressLimitExceeded, ArgumentError, AttachmentLimitExceeded, AuthFailure, Base, DuplicateLoadBalancerName, Error, IncorrectState, InstanceLimitExceeded, InsufficientAddressCapacity, InsufficientInstanceCapacity, InsufficientReservedInstanceCapacity, InsufficientReservedInstancesCapacity, InternalError, InvalidAMIAttributeItemValue, InvalidAMIIDMalformed, InvalidAMIIDNotFound, InvalidAMIIDUnavailable, InvalidAttachmentNotFound, InvalidClientTokenId, InvalidConfigurationRequest, InvalidDeviceInUse, InvalidGroupDuplicate, InvalidGroupInUse, InvalidGroupNotFound, InvalidGroupReserved, InvalidInstance, InvalidInstanceIDMalformed, InvalidInstanceIDNotFound, InvalidKeyPairDuplicate, InvalidKeyPairNotFound, InvalidManifest, InvalidParameterCombination, InvalidParameterValue, InvalidPermissionDuplicate, InvalidPermissionMalformed, InvalidReservationIDMalformed, InvalidReservationIDNotFound, InvalidReservedInstancesId, InvalidReservedInstancesOfferingId, InvalidSnapshotIDMalformed, InvalidSnapshotIDNotFound, InvalidUserIDMalformed, InvalidVolumeIDDuplicate, InvalidVolumeIDMalformed, InvalidVolumeIDNotFound, InvalidVolumeIDZoneMismatch, InvalidZoneNotFound, LoadBalancerNotFound, NonEBSInstance, PendingSnapshotLimitExceeded, ReservedInstancesLimitExceeded, Response, SignatureDoesNotMatch, SnapshotLimitExceeded, TooManyLoadBalancers, Unavailable, UnknownParameter, ValidationError, VolumeLimitExceeded

Constant Summary

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']  || ""
VERSION =
"0.9.17"

Class Method Summary (collapse)

Class Method Details

+ (String) canonical_string(params, host, method = "POST", base = "/")

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 be sorted in case-insensitive alphabetical order and must not be url encoded.

Parameters:

  • params (String)

    the params that will be sorted and encoded as a canonical string.

  • host (String)

    the hostname of the API endpoint.

  • method (String) (defaults to: "POST")

    the HTTP method that will be used to submit the params.

  • base (String) (defaults to: "/")

    the URI path that this information will be submitted to.

Returns:

  • (String)

    the canonical request description string.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/AWS.rb', line 65

def AWS.canonical_string(params, host, method="POST", base="/")
  # Sort, and encode parameters into a canonical string.
  sorted_params = params.sort {|x,y| x[0] <=> y[0]}
  encoded_params = sorted_params.collect do |p|
    encoded = (CGI::escape(p[0].to_s) +
               "=" + CGI::escape(p[1].to_s))
    # Ensure spaces are encoded as '%20', not '+'
    encoded = encoded.gsub('+', '%20')
    # According to RFC3986 (the scheme for values expected by signing requests), '~' 
    # should not be encoded
    encoded = encoded.gsub('%7E', '~')
  end
  sigquery = encoded_params.join("&")

  # Generate the request description string
  req_desc =
    method + "\n" +
    host + "\n" +
    base + "\n" +
    sigquery

end

+ (String) encode(secret_access_key, str, urlencode = true)

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.

Parameters:

  • secret_access_key (String)

    the user's secret access key for signing.

  • str (String)

    the string to be hashed and encoded.

  • urlencode (Boolean) (defaults to: true)

    whether or not to url encode the result., true or false

Returns:

  • (String)

    the signed and encoded string.



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/AWS.rb', line 97

def AWS.encode(secret_access_key, str, urlencode=true)
  digest = OpenSSL::Digest::Digest.new('sha256')
  b64_hmac =
    Base64.encode64(
      OpenSSL::HMAC.digest(digest, secret_access_key, str)).gsub("\n","")

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