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.EnvironmentCredentials

Inherits:
AWS.Credentials show all
Defined in:
lib/credentials/environment_credentials.js

Overview

Represents credentials from the environment.

By default, this class will look for the matching environment variables prefixed by a given envPrefix. The un-prefixed environment variable names for each credential value is listed below:

accessKeyId: ACCESS_KEY_ID
secretAccessKey: SECRET_ACCESS_KEY
sessionToken: SESSION_TOKEN

With the default prefix of 'AWS', the environment variables would be:

AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN

Constructor Summary collapse

Property Summary collapse

Properties inherited from AWS.Credentials

expired, expireTime, accessKeyId, secretAccessKey, sessionToken, expiryWindow

Method Summary collapse

Methods inherited from AWS.Credentials

needsRefresh, get, getPromise, refreshPromise

Constructor Details

new AWS.EnvironmentCredentials(envPrefix) ⇒ void

Creates a new EnvironmentCredentials class with a given variable prefix envPrefix. For example, to load credentials using the 'AWS' prefix:

var creds = new AWS.EnvironmentCredentials('AWS');
creds.accessKeyId == 'AKID' // from AWS_ACCESS_KEY_ID env var

Parameters:

  • envPrefix (String)

    the prefix to use (e.g., 'AWS') for environment variables. Do not include the separating underscore.

Property Details

envPrefixString (readonly)

Returns the prefix for the environment variable names excluding the separating underscore ('_').

Returns:

  • (String)

    the prefix for the environment variable names excluding the separating underscore ('_').

Method Details

refresh(callback) ⇒ void

Loads credentials from the environment using the prefixed environment variables.

Callback (callback):

  • function(err) { ... }

    Called after the (prefixed) ACCESS_KEY_ID, SECRET_ACCESS_KEY, and SESSION_TOKEN environment variables are read. When this callback is called with no error, it means that the credentials information has been loaded into the object (as the accessKeyId, secretAccessKey, and sessionToken properties).

    Parameters:

    • err (Error)

      if an error occurred, this value will be filled

See Also:

  • AWS.EnvironmentCredentials.get