You are viewing the documentation for an older major version of the AWS SDK for JavaScript.
The modular AWS SDK for JavaScript (v3), the latest major version of AWS SDK for JavaScript, is now stable and recommended for general use. For more information, see the Migration Guide and API Reference.

Class: AWS.MetadataService

Inherits:
Object
  • Object
show all
Defined in:
lib/metadata_service.js

Overview

Note:

This feature is not supported in the browser environment of the SDK.

Represents a metadata service available on EC2 instances. Using the request() method, you can receieve metadata about any available resource on the metadata service.

You can disable the use of the IMDS by setting the AWS_EC2_METADATA_DISABLED environment variable to a truthy value.

Constructor Summary collapse

Property Summary collapse

Method Summary collapse

Constructor Details

new AWS.MetadataService(options) ⇒ void

Creates a new MetadataService object with a given set of options.

Options Hash (options):

  • host (String)

    the hostname of the instance metadata service

  • httpOptions (map)

    a map of options to pass to the underlying HTTP request:

    • timeout (Number) — a timeout value in milliseconds to wait before aborting the connection. Set to 0 for no timeout.
  • maxRetries (Integer)

    the maximum number of retries to perform for timeout errors

  • retryDelayOptions (map)

    A set of options to configure the retry delay on retryable errors. See AWS.Config for details.

Property Details

disableFetchTokenBoolean (static, readwrite)

when enabled, metadata service will not fetch token

Default Value:

AWS.MetadataService.disableFetchToken = false

httpOptionsmap (readwrite)

Returns a map of options to pass to the underlying HTTP request:

  • timeout (Number) — a timeout value in milliseconds to wait before aborting the connection. Set to 0 for no timeout.

Returns:

  • (map)

    a map of options to pass to the underlying HTTP request:

    • timeout (Number) — a timeout value in milliseconds to wait before aborting the connection. Set to 0 for no timeout.

Method Details

request(path, options, callback) ⇒ void

Sends a request to the instance metadata service for a given resource.

Parameters:

  • path (String)

    the path of the resource to get

  • options (map)

    an optional map used to make request

    • method (String) — HTTP request method

    • headers (map<String,String>) — a map of response header keys and their respective values

Callback (callback):

  • function(err, data) { ... }

    Called when a response is available from the service.

    Parameters:

    • err (Error, null)

      if an error occurred, this value will be set

    • data (String, null)

      if the request was successful, the body of the response