Method: Fog::Compute::AWS::Real#initialize
- Defined in:
- lib/fog/compute/aws.rb
#initialize(options = {}) ⇒ Real
Initialize connection to EC2
Notes
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples
sdb = SimpleDB.new(
:aws_access_key_id => your_aws_access_key_id,
:aws_secret_access_key => your_aws_secret_access_key
)
Parameters
-
options<~Hash> - config arguments for connection. Defaults to {}.
-
region<~String> - optional region to use, in
- ‘eu-west-1’, ‘us-east-1’, ‘us-west-1’, ‘ap-northeast-1’, ‘ap-southeast-1’
-
Returns
-
EC2 object with connection to aws.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/fog/compute/aws.rb', line 201 def initialize(={}) require 'fog/core/parser' @aws_access_key_id = [:aws_access_key_id] @aws_secret_access_key = [:aws_secret_access_key] @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) @region = [:region] ||= 'us-east-1' if @endpoint = [:endpoint] endpoint = URI.parse(@endpoint) @host = endpoint.host @path = endpoint.path @port = endpoint.port @scheme = endpoint.scheme else @host = [:host] || case [:region] when 'ap-northeast-1' 'ec2.ap-northeast-1.amazonaws.com' when 'ap-southeast-1' 'ec2.ap-southeast-1.amazonaws.com' when 'eu-west-1' 'ec2.eu-west-1.amazonaws.com' when 'us-east-1' 'ec2.us-east-1.amazonaws.com' when 'us-west-1' 'ec2.us-west-1.amazonaws.com' else raise ArgumentError, "Unknown region: #{[:region].inspect}" end @path = [:path] || '/' @port = [:port] || 443 @scheme = [:scheme] || 'https' end @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", [:persistent]) end |