AWS.EC2MetadataCredentials — AWS SDK for JavaScript (original) (raw)

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.

Overview

Note:

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

Represents credentials received from the metadata service on an EC2 instance.

By default, this class will connect to the metadata service usingAWS.MetadataService and attempt to load any available credentials. If it can connect, and credentials are available, these will be used with zero configuration.

This credentials class will by default timeout after 1 second of inactivity and retry 3 times. If your requests to the EC2 metadata service are timing out, you can increase these values by configuring them directly:

AWS.config.credentials = new AWS.EC2MetadataCredentials({
  httpOptions: { timeout: 5000 }, // 5 second timeout
  maxRetries: 10, // retry 10 times
  retryDelayOptions: { base: 200 }, // see AWS.Config for information
  logger: console // see AWS.Config for information
  ec2MetadataV1Disabled: false // whether to block IMDS v1 fallback.
});

If your requests are timing out in connecting to the metadata service, such as when testing on a development machine, you can use the connectTimeout option, specified in milliseconds, which also defaults to 1 second.

If the requests failed or returns expired credentials, it will extend the expiration of current credential, with a warning message. For more information, please go to:https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html

Constructor Summarycollapse

Property Summarycollapse

Properties inherited from AWS.Credentials

expired, expireTime, accessKeyId, secretAccessKey, sessionToken, expiryWindow

Method Summarycollapse

Methods inherited from AWS.Credentials

needsRefresh, get, getPromise, refreshPromise

Constructor Details

new AWS.EC2MetadataCredentials(options) ⇒ void

Property Details

originalExpiration ⇒ Object

The original expiration of the current credential. In case of AWS outage, the EC2 metadata will extend expiration of the existing credential.

Method Details

refresh(callback) ⇒ void

Loads the credentials from the instance metadata service