Class: Aws::InstanceProfileCredentials
- Inherits:
-
Object
- Object
- Aws::InstanceProfileCredentials
- Includes:
- CredentialProvider, RefreshingCredentials
- Defined in:
- lib/aws-sdk-core/instance_profile_credentials.rb
Overview
An auto-refreshing credential provider that loads credentials from EC2 instances.
instance_credentials = Aws::InstanceProfileCredentials.new
ec2 = Aws::EC2::Client.new(credentials: instance_credentials)
## Retries When initialized from the default credential chain, this provider defaults to 0 retries. Breakdown of retries is as follows:
* **Configurable retries** (defaults to `1`): these retries handle errors when communicating
with the IMDS endpoint. There are two separate retry mechanisms within the provider:
* Entire token fetch and credential retrieval process
* Token fetching
* **JSON parsing retries**: Fixed at 3 attempts to handle cases when IMDS returns malformed JSON
responses. These retries are separate from configurable retries.
Defined Under Namespace
Classes: Non200Response, Token, TokenExpiredError, TokenRetrivalError
Constant Summary collapse
- NETWORK_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
These are the errors we trap when attempting to talk to the instance metadata service. Any of these imply the service is not present, no responding or some other non-recoverable error.
[ Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::ENETUNREACH, SocketError, Timeout::Error, Non200Response ].freeze
- METADATA_PATH_BASE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path base for GET request for profile and credentials
'/latest/meta-data/iam/security-credentials/'.freeze
- METADATA_TOKEN_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Path for PUT request for token
'/latest/api/token'.freeze
Constants included from RefreshingCredentials
RefreshingCredentials::ASYNC_EXPIRATION_LENGTH, RefreshingCredentials::CLIENT_EXCLUDE_OPTIONS, RefreshingCredentials::SYNC_EXPIRATION_LENGTH
Instance Attribute Summary collapse
- #backoff ⇒ Proc readonly
- #disable_imds_v1 ⇒ Boolean readonly
- #endpoint ⇒ String readonly
- #http_debug_output ⇒ IO? readonly
- #http_open_timeout ⇒ Integer readonly
- #http_read_timeout ⇒ Integer readonly
- #port ⇒ Integer readonly
- #retries ⇒ Integer readonly
- #token_ttl ⇒ Integer readonly
Attributes included from CredentialProvider
#credentials, #expiration, #metrics
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ InstanceProfileCredentials
constructor
A new instance of InstanceProfileCredentials.
Methods included from RefreshingCredentials
Methods included from CredentialProvider
Constructor Details
#initialize(options = {}) ⇒ InstanceProfileCredentials
Returns a new instance of InstanceProfileCredentials.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 89 def initialize( = {}) @backoff = resolve_backoff([:backoff]) @disable_imds_v1 = resolve_disable_v1() @endpoint = resolve_endpoint() @http_open_timeout = [:http_open_timeout] || 1 @http_read_timeout = [:http_read_timeout] || 1 @http_debug_output = [:http_debug_output] @port = [:port] || 80 @retries = [:retries] || 1 @token_ttl = [:token_ttl] || 21_600 @async_refresh = false @imds_v1_fallback = false @no_refresh_until = nil @token = nil @metrics = ['CREDENTIALS_IMDS'] super end |
Instance Attribute Details
#backoff ⇒ Proc (readonly)
118 119 120 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 118 def backoff @backoff end |
#disable_imds_v1 ⇒ Boolean (readonly)
109 110 111 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 109 def disable_imds_v1 @disable_imds_v1 end |
#endpoint ⇒ String (readonly)
121 122 123 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 121 def endpoint @endpoint end |
#http_debug_output ⇒ IO? (readonly)
133 134 135 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 133 def http_debug_output @http_debug_output end |
#http_open_timeout ⇒ Integer (readonly)
127 128 129 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 127 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Integer (readonly)
130 131 132 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 130 def http_read_timeout @http_read_timeout end |
#port ⇒ Integer (readonly)
124 125 126 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 124 def port @port end |
#retries ⇒ Integer (readonly)
115 116 117 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 115 def retries @retries end |
#token_ttl ⇒ Integer (readonly)
112 113 114 |
# File 'lib/aws-sdk-core/instance_profile_credentials.rb', line 112 def token_ttl @token_ttl end |