@aws-sdk/credential-providers package exports a set of factory functions that each return an AwsCredentialIdentityProvider — an async function that resolves AWS credentials from a specific source. Pass any provider directly to the credentials option of any SDK client.
Using a provider with a client
expiration date.
Providers
fromEnv() — environment variables
fromEnv() — environment variables
@aws-sdk/credential-providersEnvironments: Node.js onlyReads static credentials from environment variables. Throws if
AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY are missing or empty.Reads these variables:| Variable | Required | Description |
|---|---|---|
AWS_ACCESS_KEY_ID | Yes | Access key ID |
AWS_SECRET_ACCESS_KEY | Yes | Secret access key |
AWS_SESSION_TOKEN | No | Session token for temporary credentials |
AWS_CREDENTIAL_EXPIRATION | No | ISO-8601 expiration timestamp |
fromIni(options?) — shared INI files
fromIni(options?) — shared INI files
fromNodeProviderChain(options?) — default Node.js chain
fromNodeProviderChain(options?) — default Node.js chain
@aws-sdk/credential-providersEnvironments: Node.js onlyThe same credential chain used automatically by Node.js SDK clients. Useful when you need a provider reference explicitly — for example, when constructing a presigner or RDS signer utility outside of a client.Tries the following sources in order, stopping at the first success:
- Environment variables (
fromEnv) - SSO token cache (
fromSSO) - Web identity token file (
fromTokenFile) - Shared INI files (
fromIni) - Container metadata (
fromContainerMetadata) - EC2 instance metadata (
fromInstanceMetadata)
fromSSO(options) — AWS SSO / Identity Center
fromSSO(options) — AWS SSO / Identity Center
@aws-sdk/credential-providersEnvironments: Node.js only
Inner clients used:
@aws-sdk/client-sso, @aws-sdk/client-sso-oidcReads a cached SSO access token from disk (written by aws configure sso or aws sso login) and exchanges it for temporary AWS credentials.Login flow:~/.aws/config:fromTemporaryCredentials(options) — assume a role via STS
fromTemporaryCredentials(options) — assume a role via STS
@aws-sdk/credential-providersEnvironments: Node.js, browsers, native apps
Inner clients used:
@aws-sdk/client-stsCalls STS AssumeRole to obtain short-lived credentials for the specified role. Supports chaining role assumptions and MFA.fromWebToken(options) — web identity / OIDC
fromWebToken(options) — web identity / OIDC
@aws-sdk/credential-providersEnvironments: Node.js, browsers, native apps
Inner clients used:
@aws-sdk/client-stsExchanges an OAuth 2.0 or OpenID Connect token for temporary AWS credentials by calling STS AssumeRoleWithWebIdentity. Supported identity providers include Login with Amazon, Facebook Login, and Google Sign-In.fromTokenFile() instead.fromTokenFile(options?) — web identity token file
fromTokenFile(options?) — web identity token file
@aws-sdk/credential-providersEnvironments: Node.js only
Inner clients used:
@aws-sdk/client-stsReads an OIDC token from a file on disk and calls STS AssumeRoleWithWebIdentity. Configuration can come from options or environment variables.| Option | Environment variable | Required | Description |
|---|---|---|---|
webIdentityTokenFile | AWS_WEB_IDENTITY_TOKEN_FILE | Yes | Path to the token file |
roleArn | AWS_ROLE_ARN | Yes | Role to assume |
roleSessionName | AWS_ROLE_SESSION_NAME | No | Session name |
fromContainerMetadata() — ECS task role
fromContainerMetadata() — ECS task role
@aws-sdk/credential-providersEnvironments: Node.js onlyRetrieves credentials for the IAM role associated with the current ECS task from the container metadata service. Requires the task to have an IAM role configured.
fromInstanceMetadata() — EC2 instance profile
fromInstanceMetadata() — EC2 instance profile
@aws-sdk/credential-providersEnvironments: Node.js onlyRetrieves credentials for the IAM role attached to the current EC2 instance from the instance metadata service. Both IMDSv1 and IMDSv2 are supported.
fromCognitoIdentity(options) — Cognito Identity
fromCognitoIdentity(options) — Cognito Identity
@aws-sdk/credential-providersEnvironments: Node.js, browsers, native apps
Inner clients used:
@aws-sdk/client-cognito-identityRetrieves AWS credentials for a known Cognito Identity ID by calling the GetCredentialsForIdentity API. Use when you already have an identity ID.fromCognitoIdentityPool(options) — Cognito Identity Pool
fromCognitoIdentityPool(options) — Cognito Identity Pool
@aws-sdk/credential-providersEnvironments: Node.js, browsers, native apps
Inner clients used:
@aws-sdk/client-cognito-identityCalls GetId to obtain a Cognito identity ID from an identity pool, then calls GetCredentialsForIdentity to retrieve credentials. The identity ID is cached internally; credentials are not.fromHttp(options) — HTTP/HTTPS endpoint
fromHttp(options) — HTTP/HTTPS endpoint
@aws-sdk/credential-providersEnvironments: Node.js, browsers (HTTPS only in browsers)Makes an HTTP(S) GET request to a credential-serving endpoint and parses JSON credentials from the response. A general form of
fromContainerMetadata. Accepts HTTPS URLs or a limited set of HTTP endpoints (loopback, ECS/EKS metadata hosts).| Variable | Description |
|---|---|
AWS_CONTAINER_CREDENTIALS_FULL_URI | Full URI to the credential endpoint |
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | Path appended to 169.254.170.2 |
AWS_CONTAINER_AUTHORIZATION_TOKEN | Authorization token value |
AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE | Path to file containing the token |
fromLoginCredentials(options?) — aws login cache
fromLoginCredentials(options?) — aws login cache
@aws-sdk/credential-providersEnvironments: Node.js only
Inner clients used:
@aws-sdk/client-signinReads cached credentials stored on disk after running aws login. Useful when users authenticate via the AWS Management Console experience. Part of fromNodeProviderChain.createCredentialChain(...providers) — custom chain
createCredentialChain(...providers) — custom chain
@aws-sdk/credential-providersEnvironments: Node.js, browsers, native appsComposes multiple provider functions into a single provider. The chain tries each provider in order and returns the first successful result. You can mix built-in providers with your own async functions.
expireAfter:Use .expireAfter(milliseconds) to set a client-side expiry on credentials that don’t include one. This causes the chain to be re-evaluated before the expiry window closes (5 minutes before expiry).Region resolution in credential providers
When a credential provider uses an inner client (STS, SSO, Cognito), the region for that inner client is resolved in this priority order:clientConfig.regionpassed directly to the credential provider- The
regionfield in the active profile (when resolving from config file) - The outer SDK client’s region
AWS_REGIONenvironment variableus-east-1fallback (legacy)
clientConfig: