@aws-sdk/credential-providers is a collection of factory functions that each return an AwsCredentialIdentityProvider. Pass the result to any SDK client’s credentials option.
AwsCredentialIdentityProvider type
Every function in this package returns the same type:
expiration, at which point it calls the provider again.
fromEnv()
Reads credentials from environment variables. Not available in browsers.
| Variable | Required | Description |
|---|---|---|
AWS_ACCESS_KEY_ID | Yes | AWS access key |
AWS_SECRET_ACCESS_KEY | Yes | AWS secret key |
AWS_SESSION_TOKEN | No | Session token for temporary credentials |
AWS_CREDENTIAL_EXPIRATION | No | ISO-8601 expiration timestamp |
AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is missing.
fromIni(options?)
Reads from ~/.aws/credentials and ~/.aws/config. May use @aws-sdk/client-sts or @aws-sdk/client-sso internally. Not available in browsers.
Profile to read from the credentials/config file. Defaults to the value of
AWS_PROFILE, then default. If the parent client has profile set, that value is inherited unless overridden here.Path to the shared credentials file. Falls back to
AWS_SHARED_CREDENTIALS_FILE environment variable.Path to the shared config file. Falls back to
AWS_CONFIG_FILE environment variable.Required when the selected profile uses MFA (
mfa_serial). Called with the MFA serial ARN; must return the one-time token.When
true, always reloads credentials from the filesystem instead of using cached values. Useful for detecting credential file changes at runtime.Configuration overrides passed to any inner STS or SSO client instantiated during credential resolution.
fromNodeProviderChain(options?)
The default credential chain used by Node.js SDK clients. Useful for utility functions (presigners, RDS signer) that need credentials outside a client context. Not available in browsers.
Attempts each source in order, stopping at the first that succeeds:
- Environment variables (
fromEnv) - SSO token cache (
fromSSO) - Web identity token file (
fromTokenFile) - Shared INI files (
fromIni) - EC2/ECS instance metadata (
fromContainerMetadata,fromInstanceMetadata)
Passed to any inner credentials client (STS, SSO, etc.) instantiated during the chain.
You do not need to call
fromNodeProviderChain explicitly when constructing an SDK client — it is the default. Use it when you need a credential provider reference for something like getSignedUrl.fromSSO(options)
Reads cached SSO access tokens from disk and exchanges them for temporary AWS credentials. Uses @aws-sdk/client-sso and @aws-sdk/client-sso-oidc. Not available in browsers.
profile:
Profile name in
~/.aws/config or ~/.aws/credentials. Required when not passing inline sso* parameters.The URL to the AWS SSO portal (e.g.,
https://d-abc123.awsapps.com/start). Required if using inline SSO params.AWS account ID for the SSO session. Required if using inline SSO params.
AWS region where the SSO service is hosted. Required if using inline SSO params.
Name of the IAM role to assume via SSO. Required if using inline SSO params.
Named SSO session as configured in
~/.aws/config with [sso-session] sections.Path to the shared credentials file.
Path to the shared config file.
Configuration overrides for the inner SSO client.
fromTemporaryCredentials(options)
Assumes an IAM role via STS AssumeRole and returns temporary credentials. Uses @aws-sdk/client-sts. Available in browsers and native apps.
Parameters passed directly to the STS
AssumeRole API. Must include RoleArn. RoleSessionName defaults to a random value prefixed with aws-sdk-js-.ARN of the role to assume.
Identifier for the assumed role session. Auto-generated if omitted.
Duration of the role session in seconds.
Credentials used to call STS. Defaults to the standard credential chain if omitted.
Required when
params.SerialNumber is set. Must return the MFA token.Configuration overrides for the inner STS client.
fromWebToken(options)
Calls STS AssumeRoleWithWebIdentity using an OIDC/OAuth2 token. Uses @aws-sdk/client-sts. Available in browsers and native apps.
ARN of the role to assume.
The OAuth 2.0 access token or OpenID Connect ID token from the identity provider.
Identifier for the assumed role session.
The fully qualified domain name of the identity provider (e.g.,
graph.facebook.com).ARNs of IAM managed policies to use as managed session policies.
An inline session policy in JSON format.
Duration of the role session in seconds.
Configuration overrides for the inner STS client.
fromTokenFile(options?)
Reads an OIDC token from a file path and calls STS AssumeRoleWithWebIdentity. Configuration is typically provided via environment variables in Kubernetes/EKS environments. Uses @aws-sdk/client-sts. Not available in browsers.
| Option | Environment variable | Required | Description |
|---|---|---|---|
webIdentityTokenFile | AWS_WEB_IDENTITY_TOKEN_FILE | Yes | Path to the OIDC token file |
roleArn | AWS_ROLE_ARN | Yes | IAM role ARN to assume |
roleSessionName | AWS_ROLE_SESSION_NAME | No | Session name |
Configuration overrides for the inner STS client.
fromContainerMetadata(options?)
Reads credentials from the ECS container metadata service. Returns credentials for the IAM role associated with the ECS task. Not available in browsers.
Connection timeout in milliseconds for requests to the metadata service.
Maximum number of times to retry failed HTTP connections to the metadata service.
fromInstanceMetadata(options?)
Reads credentials from the EC2 Instance Metadata Service (IMDS). Supports both IMDSv1 and IMDSv2. Not available in browsers.
Connection timeout in milliseconds.
Maximum number of HTTP connection retries.
fromHttp(options)
Makes a GET request to an HTTP(S) endpoint to retrieve credentials. This is a general form of fromContainerMetadata. Available in browsers (HTTPS only) and Node.js. The server must respond with:
- Node.js
- Browser
Full URI to request credentials from. Mutually exclusive with
awsContainerCredentialsRelativeUri. Falls back to AWS_CONTAINER_CREDENTIALS_FULL_URI.Relative URI appended to the link-local host
169.254.170.2. Falls back to AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.Value for the
Authorization request header. Falls back to AWS_CONTAINER_AUTHORIZATION_TOKEN.Path to a file containing the authorization token. Falls back to
AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE.127.0.0.0/8, [::1/128]), ECS container host (169.254.170.2), and EKS container host (169.254.170.23, [fd00:ec2::23]).
fromCognitoIdentity(options)
Retrieves credentials for a specific Cognito identity ID using the GetCredentialsForIdentity API. Uses @aws-sdk/client-cognito-identity. Available in browsers and native apps.
The unique Cognito identity ID against which credentials will be issued.
Map of identity provider names to tokens. Required when using external identity providers (Facebook, Google, Amazon, Twitter).
ARN of the role to assume when multiple roles were received from the identity provider token.
Configuration overrides for the inner Cognito Identity client.
fromCognitoIdentityPool(options)
Calls GetId to obtain a Cognito identity ID, then calls GetCredentialsForIdentity to get temporary credentials. The identity ID is cached internally. Uses @aws-sdk/client-cognito-identity. Available in browsers and native apps.
The Cognito identity pool ID from which to retrieve or generate an identity.
Map of identity provider names to tokens.
Standard AWS account ID (9+ digits).
ARN of the role to assume when multiple roles are available.
Custom storage object for caching resolved Cognito identity IDs.
A unique identifier for the user, used as a cache key for identity IDs.
Configuration overrides for the inner Cognito Identity client.
fromProcess(options?)
Runs a process defined in the credential_process field of the AWS config/credentials file and reads JSON credentials from its standard output. Not available in browsers.
Profile to read from. Inherits from the parent client’s profile if set.
Path to the shared credentials file.
Path to the shared config file.
createCredentialChain(...providers)
Composes multiple credential providers into a single provider that tries each in order, resolving with the first one that succeeds.
expireAfter:
One or more credential providers to try in order. Custom
async functions returning AwsCredentialIdentity are also accepted..expireAfter(milliseconds) — Chainable method that sets a client-side TTL on the returned credentials. When the expiration approaches within 5 minutes, the chain is invoked again. If omitted and no provider sets an expiration, the chain is only called once per client.
Region resolution in credential providers
When a credential provider uses an inner client (e.g., STS forfromTemporaryCredentials), the region for that inner client follows this priority order:
clientConfig.region— passed directly to the credential provider- Profile region — from the config file for the active profile (when resolving from config)
- Parent client region — the region of the SDK client using these credentials
AWS_REGIONenvironment variable- Profile region — lower priority when not resolving from config
us-east-1— legacy fallback
clientConfig: { region: "us-east-1" } to any provider that accepts it to ensure consistent STS/SSO request routing.
fromLoginCredentials(options?)
Reads cached credentials stored on disk after authenticating with the AWS CLI’s aws login command. Not available in browsers. Uses @aws-sdk/client-signin internally.
This provider is typically used automatically via fromNodeProviderChain. Use it explicitly only if you need to control which profile to load.
Profile name to load. Defaults to the parent client’s
profile field, then default.Configuration overrides for the inner signin client. Setting
region here overrides the profile region.