We announced the upcoming end-of-support for AWS SDK for JavaScript v2.
We recommend that you migrate to AWS SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

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.

  • ec2MetadataV1Disabled (boolean)

    Whether to block IMDS v1 fallback.

  • profile (string)

    A profile to check for IMDSv1 fallback settings.

  • filename (string)

    Optional filename for the config file.

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