Class: AWS::Core::CredentialProviders::EC2Provider

Inherits:
Object
  • Object
show all
Includes:
Provider
Defined in:
lib/aws/core/credential_providers.rb

Overview

This credential provider tries to get credentials from the EC2 metadata service.

Constant Summary

Constants included from Provider

Provider::KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Provider

#access_key_id, #refresh, #secret_access_key, #session_token

Constructor Details

#initialize(options = {}) ⇒ EC2Provider

Returns a new instance of EC2Provider.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ip_address (String) — default: '169.254.169.254'
  • :port (Integer) — default: 80
  • :http_open_timeout (Float) — default: 1
  • :http_read_timeout (Float) — default: 1
  • :http_debug_output (Object) — default: nil

    HTTP wire traces are sent to this object. You can specify something like $stdout.



236
237
238
239
240
241
242
# File 'lib/aws/core/credential_providers.rb', line 236

def initialize options = {}
  @ip_address = options[:ip_address] || '169.254.169.254'
  @port = options[:port] || 80
  @http_open_timeout = options[:http_open_timeout] || 1
  @http_read_timeout = options[:http_read_timeout] || 1
  @http_debug_output = options[:http_debug_output]
end

Instance Attribute Details

#credentials_expirationTime?

Returns:

  • (Time, nil)


260
261
262
# File 'lib/aws/core/credential_providers.rb', line 260

def credentials_expiration
  @credentials_expiration
end

#http_debug_outputObject?

Returns:

  • (Object, nil)


257
258
259
# File 'lib/aws/core/credential_providers.rb', line 257

def http_debug_output
  @http_debug_output
end

#http_open_timeoutFloat

Returns:

  • (Float)


251
252
253
# File 'lib/aws/core/credential_providers.rb', line 251

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutFloat

Returns:

  • (Float)


254
255
256
# File 'lib/aws/core/credential_providers.rb', line 254

def http_read_timeout
  @http_read_timeout
end

#ip_addressString

Returns Defaults to ‘169.254.169.254’.

Returns:

  • (String)

    Defaults to ‘169.254.169.254’.



245
246
247
# File 'lib/aws/core/credential_providers.rb', line 245

def ip_address
  @ip_address
end

#portInteger

Returns Defaults to port 80.

Returns:

  • (Integer)

    Defaults to port 80.



248
249
250
# File 'lib/aws/core/credential_providers.rb', line 248

def port
  @port
end

Instance Method Details

#credentialsHash

Refresh provider if existing credentials will be expired in 5 min

Returns:

  • (Hash)

    Returns a hash of credentials containg at least the :access_key_id and :secret_access_key. The hash may also contain a :session_token.

Raises:



270
271
272
273
274
275
# File 'lib/aws/core/credential_providers.rb', line 270

def credentials
  if @credentials_expiration && @credentials_expiration.utc <= Time.now.utc - 5 * 60
    refresh
  end
  super
end