You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

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

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, #set?

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
  • :retries (Integer) — default: 0

    Number of times to retry retrieving credentials.

  • :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.



364
365
366
367
368
369
370
371
# File 'lib/aws/core/credential_providers.rb', line 364

def initialize options = {}
  @ip_address = options[:ip_address] || '169.254.169.254'
  @port = options[:port] || 80
  @retries = options[:retries] || 0
  @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)


392
393
394
# File 'lib/aws/core/credential_providers.rb', line 392

def credentials_expiration
  @credentials_expiration
end

#http_debug_outputObject?

Returns:

  • (Object, nil)


389
390
391
# File 'lib/aws/core/credential_providers.rb', line 389

def http_debug_output
  @http_debug_output
end

#http_open_timeoutFloat

Returns:

  • (Float)


383
384
385
# File 'lib/aws/core/credential_providers.rb', line 383

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutFloat

Returns:

  • (Float)


386
387
388
# File 'lib/aws/core/credential_providers.rb', line 386

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'.



374
375
376
# File 'lib/aws/core/credential_providers.rb', line 374

def ip_address
  @ip_address
end

#portInteger

Returns Defaults to port 80.

Returns:

  • (Integer)

    Defaults to port 80.



377
378
379
# File 'lib/aws/core/credential_providers.rb', line 377

def port
  @port
end

#retriesInteger

Returns Defaults to 0

Returns:

  • (Integer)

    Defaults to 0



380
381
382
# File 'lib/aws/core/credential_providers.rb', line 380

def retries
  @retries
end

Instance Method Details

#credentialsHash

Refresh provider if existing credentials will be expired in 15 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:



402
403
404
405
# File 'lib/aws/core/credential_providers.rb', line 402

def credentials
  refresh if near_expiration?
  super
end