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).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aws-sdk-core/ec2_metadata.rb', line 57 def initialize( = {}) @token_ttl = [:token_ttl] || 21_600 @retries = [:retries] || 3 @backoff = backoff([:backoff]) endpoint_mode = [:endpoint_mode] || 'IPv4' @endpoint = resolve_endpoint([:endpoint], endpoint_mode) @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
This implementation always returns a String and will not parse any responses. Parsable responses may include JSON objects or directory listings, which are strings separated by line feeds (ASCII 10).
Unlike other services, IMDS does not have a service API model. This means that we cannot confidently generate code with methods and response structures. This implementation ensures that new IMDS features are always supported by being deployed to the instance and does not require code changes.
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.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/aws-sdk-core/ec2_metadata.rb', line 110 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 |