Class: Aws::EC2Metadata
- Inherits:
-
Object
- Object
- Aws::EC2Metadata
- Defined in:
- lib/aws-sdk-core/ec2_metadata.rb
Overview
A client that can query version 2 of the EC2 Instance Metadata
Defined Under Namespace
Classes: MetadataNotFoundError, RequestForbiddenError, Token, TokenExpiredError, TokenRetrievalError
Constant Summary collapse
- 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
Instance Method Summary collapse
-
#get(path) ⇒ Object
Fetches a given metadata category using a String path, and returns the result as a String.
-
#initialize(options = {}) ⇒ EC2Metadata
constructor
Creates a client that can query version 2 of the EC2 Instance Metadata service (IMDS).
Constructor Details
#initialize(options = {}) ⇒ EC2Metadata
Customers using containers may need to increase their hop limit to access IMDSv2.
Creates a client that can query version 2 of the EC2 Instance Metadata
service (IMDS).
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/aws-sdk-core/ec2_metadata.rb', line 53 def initialize( = {}) @token_ttl = [:token_ttl] || 21_600 @retries = [:retries] || 3 @backoff = backoff([:backoff]) @endpoint = [:endpoint] || '169.254.169.254' @port = [:port] || 80 @http_open_timeout = [:http_open_timeout] || 1 @http_read_timeout = [:http_read_timeout] || 1 @http_debug_output = [:http_debug_output] @token = nil @mutex = Mutex.new end |
Instance Method Details
#get(path) ⇒ Object
Fetches a given metadata category using a String path, and returns the
result as a String. A path starts with the API version (usually
"/latest/"). See the instance data categories for possible paths.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/aws-sdk-core/ec2_metadata.rb', line 105 def get(path) retry_errors(max_retries: @retries) do @mutex.synchronize do fetch_token unless @token && !@token.expired? end open_connection do |conn| http_get(conn, path, @token.value) end end end |