"Could Not Load Credentials From Any Providers" (AWS SDK for JavaScript v3), Fixed: Local, SSO, Docker, GitHub Actions, Lambda, ECS, Browser and LocalStack
"CredentialsProviderError: Could not load credentials from any providers" means the AWS SDK for JavaScript v3 checked every place it looks for credentials and found none it could use. In Node.js it tries, in order: environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY), AWS IAM Identity Center (SSO), the shared ~/.aws/config and credentials files for the profile in AWS_PROFILE (or default), a credential process, a web identity token file, and finally the ECS container and EC2 instance metadata services. The fix depends on where your code runs: on your laptop, set AWS_PROFILE to a profile that exists and run aws sso login if it uses SSO; in Docker, pass environment variables or mount ~/.aws, and on EC2 raise the metadata hop limit to 2; in GitHub Actions, use aws-actions/configure-aws-credentials with an OIDC role; on Lambda, ECS and EC2, attach an IAM role; with LocalStack, set any dummy keys. In a browser there is no default chain at all, so you must supply credentials, usually through Amazon Cognito. Below: a one-minute test that shows which source is failing, then each environment step by step.
Ethan wrote a small Node.js script for Jake's computer shop: every night it uploads the day's repair photos to S3. On his laptop it worked perfectly. Copied to the back-room PC in a Docker container, it died with "Could not load credentials from any providers." Moved to GitHub Actions for a test, it died with the same words. Same code, same error, three different causes. The message is the SDK saying "I looked everywhere I know," and the fix is always about which of those places should have had the answer.
Using Python, Java, the CLI or Terraform instead? The same problem has its own page for each; see our CLI credentials guide and the cards below.
How the SDK looks for credentials (the provider chain)
When you create a client such as new S3Client({}) without passing credentials, the SDK uses its default credential provider chain: a list of places to look, tried in order until one returns usable credentials. In Node.js, version 3 of the SDK checks:
- Environment variables:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEYand, for temporary credentials,AWS_SESSION_TOKEN. - IAM Identity Center (SSO): a profile configured for SSO, with a valid login cached by
aws sso login. - Shared config and credentials files:
~/.aws/credentialsand~/.aws/config, for the profile named inAWS_PROFILE, ordefault. A profile can hold keys, or point to a role to assume, a credential process, or another source. - Login credentials: credentials from the CLI's newer sign-in flow.
- A credential process: an external program named in the config that prints credentials.
- A web identity token file:
AWS_WEB_IDENTITY_TOKEN_FILEplusAWS_ROLE_ARN, used by Kubernetes (EKS) service accounts and some CI systems. - ECS container credentials: the task role, through variables ECS sets for you.
- EC2 instance metadata: the instance profile role, from the metadata service at 169.254.169.254.
"Could not load credentials from any providers" means every one of those came back empty. The useful question is never "why can't it find credentials" in general, but "which of these should have provided them here, and why didn't it?" On a laptop that is usually step 2 or 3; in a container, step 1 or 8; in CI, step 1 or 6.
One difference from the older SDK (version 2) catches people migrating old code: v3 reads ~/.aws/config automatically, so AWS_SDK_LOAD_CONFIG=1 is no longer needed and does nothing. Region is a separate setting; a missing Region produces a different error ("Region is missing"), not this one.
The environment variables the SDK reads
| Variable | What it does |
|---|---|
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY | Credentials directly; first in the chain |
AWS_SESSION_TOKEN | Needed with temporary credentials (keys starting ASIA) |
AWS_PROFILE | Which profile in the shared files to use (default: default) |
AWS_REGION | The Region; not a credential, but needed for every call |
AWS_CONFIG_FILE, AWS_SHARED_CREDENTIALS_FILE | Use files in a non-standard place, such as a mounted folder |
AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN | Exchange a token file for a role (EKS service accounts, some CI) |
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | Set by ECS when a task role exists; leave it alone |
AWS_EC2_METADATA_DISABLED | Set to true to skip the EC2 metadata lookup, which speeds up failures off EC2 |
A quick way to see which of these exist where your app runs: env | grep ^AWS_ on macOS and Linux, or Get-ChildItem Env:AWS_* in PowerShell. A stray AWS_ACCESS_KEY_ID from an old experiment silently wins over everything else in the chain, so this check also finds the opposite problem: the "wrong" credentials being used.
Find the failing source in one minute
Before changing anything, test the chain on its own, outside your application. Save this as whoami.mjs next to your project (it uses the packages your app already has, or npm install @aws-sdk/credential-providers @aws-sdk/client-sts):
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
const creds = await fromNodeProviderChain()();
console.log("Found keys starting", creds.accessKeyId.slice(0, 4), "expires", creds.expiration ?? "never");
const sts = new STSClient({ region: process.env.AWS_REGION || "us-east-1" });
console.log(await sts.send(new GetCallerIdentityCommand({})));Run it with node whoami.mjs in exactly the environment that fails: the same terminal, container or CI job. Three possible outcomes:
- It prints an identity (an ARN). Credentials load fine in this environment; your application is overriding them (passing empty credentials, a wrong profile, or a different environment). Search your code for
credentials:andprofile:. - It fails with the same error. The environment has no usable credentials; read the section for where it runs.
- Credentials load but GetCallerIdentity fails (expired token, invalid signature). The source was found but its credentials are stale or wrong; refresh them.
Key prefixes help too: AKIA means long-term access keys; ASIA means temporary credentials (SSO, roles, metadata), which expire.
Jake: "So the script tells you which drawer is empty?"
Ethan: "It tells me whether any drawer has a key. Then I know whether to blame the computer or my code."
On your own computer: profiles and SSO
Most laptop failures come down to the profile:
- No profile named. With no
AWS_PROFILE, the SDK usesdefault. If your credentials live under a named profile, such as[profile shop], set it:export AWS_PROFILE=shopon macOS and Linux,$env:AWS_PROFILE="shop"in PowerShell, orset AWS_PROFILE=shopin Command Prompt. - A profile name typo, or the wrong file format. In
~/.aws/config, named profiles are written[profile shop]; in~/.aws/credentialsthey are written[shop]. Mixing them up means the SDK cannot find the profile. Our config vs credentials guide shows the rules side by side. - An expired SSO login. SSO profiles need a fresh login every so often:
aws sso login --profile shop. When the cached login has expired, the SSO step fails, and if nothing else in the chain has credentials, you get this error. - Running as a different user.
sudo node app.js, a Windows service or a scheduled task runs as another user, with another home folder and no~/.aws. Point it at the files withAWS_CONFIG_FILEandAWS_SHARED_CREDENTIALS_FILE, or run it as your user. - Environment variables set in one terminal only. A variable exported in one terminal is not seen by an app started from an IDE, a different terminal, or a process manager such as PM2. Set it where the app is actually launched.
To confirm what the CLI sees with the same profile, run aws sts get-caller-identity --profile shop. If the CLI works and Node does not, compare the environment the two run in: the profile setting is nearly always the difference.
Setting up an SSO profile for Node.js, start to finish
If your company uses IAM Identity Center (SSO), which is the recommended way to work locally, a profile set up once covers the CLI and every SDK, including JavaScript v3:
- Run
aws configure ssoand answer the prompts: a session name, your organization's start URL, its Region, then pick the account and role. Give the profile a short name such asshop. - Check the result in
~/.aws/config: an[sso-session ...]section with the start URL, and a[profile shop]section that refers to it withsso_session,sso_account_idandsso_role_name. - Log in:
aws sso login --profile shopopens your browser; approve, and the login is cached on disk. - Point Node at the profile:
export AWS_PROFILE=shop(or the PowerShell equivalent), plusAWS_REGION. - Verify with the test script above; it should print your role's ARN.
- When it stops working one morning, repeat step 3. SSO logins expire after the session length your organization sets, and an expired login is the single most common cause of this error on developer machines.
Once the login is cached, the SDK exchanges it for short-lived role credentials and refreshes them as needed while the login lasts; you do not copy any keys anywhere.
In Docker: no home folder, no metadata, or both
A container starts with an empty home directory and its own network, so the two sources that work on a laptop (files) and on EC2 (metadata) can both disappear. Choose one approach:
- Pass environment variables:
docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION myimage. Writing-e NAMEwithout a value copies it from your current shell, so the keys never appear in your command history. - Mount your AWS folder read-only for local development:
docker run -v "$HOME/.aws:/root/.aws:ro" -e AWS_PROFILE=shop myimage. If the container runs as a non-root user, mount it into that user's home instead, or setAWS_CONFIG_FILEandAWS_SHARED_CREDENTIALS_FILEto the mounted paths. - Use the instance's role on EC2. Containers on an EC2 instance can use the instance profile, but only if they can reach the metadata service. With IMDSv2 and the default hop limit of 1, the extra network hop of Docker's bridge network blocks it, and the SDK falls through to this error. Raise the limit to 2:
💻 Where to run these commands
Easiest: AWS CloudShell, nothing to install. Sign in to the AWS Management Console, choose your Region at the top right, then click the CloudShell icon (a small >_ terminal symbol) in the top bar, or type CloudShell in the search box and open it. When the $ prompt appears, paste a command and press Enter. CloudShell already has the AWS CLI, uses your console permissions and costs nothing extra.
On your own computer: install AWS CLI version 2 (installers for Windows, macOS and Linux are on the AWS CLI page), run aws configure once (or aws configure sso if your company signs in through single sign-on), and check it works with aws sts get-caller-identity. Then paste commands into Terminal on Mac or Linux, or PowerShell or Command Prompt on Windows.
Windows tip: a line ending in a backslash ( \ ) continues on the next line in CloudShell, Mac and Linux. In PowerShell use a backtick ( ` ) instead, in Command Prompt a caret ( ^ ), or simply join the lines into one. JSON inside single quotes works as shown in CloudShell; on Windows, save the JSON in a file and pass it as file://name.json.
Python examples: save the code in a file such as script.py, install the AWS SDK with pip install boto3, and run python script.py (python3 on Mac and Linux). It uses the same credentials as the AWS CLI; CloudShell has Python and boto3 ready.
Replace example values such as my-bucket, my-function, 111122223333 (an account ID) and us-east-1 with your own.
aws ec2 modify-instance-metadata-options \ --instance-id i-0123456789abcdef0 \ --http-put-response-hop-limit 2 \ --http-endpoint enabled
Keys baked into an image with ENV or a copied credentials file go wherever the image goes: anyone with the image has the keys, and they end up in registries and build caches. For Python in the same situation, our boto3 NoCredentialsError guide covers the equivalent fixes.
Jake: "So the back-room PC failed because the container couldn't see Ethan's laptop keys?"
Ethan: "It couldn't see any keys. A container is a new, empty computer. You have to hand it the keys on purpose."
In GitHub Actions and other CI systems
CI runners start clean every time, with no profile and no metadata, so the SDK finds nothing unless the workflow provides credentials. The secure way on GitHub is OIDC: the workflow proves its identity to AWS and receives short-lived role credentials, with no stored keys at all.
permissions:
id-token: write # required for OIDC
contents: read
jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::111122223333:role/GitHubActionsShopUpload
aws-region: us-east-1
- run: npm ci
- run: node upload.mjsThe action exports the role's temporary credentials as environment variables, which the SDK picks up at step 1 of the chain. On the AWS side you need, once: an IAM OIDC identity provider for token.actions.githubusercontent.com, and a role whose trust policy allows your repository (limit it to your repo and branch). The two most common failures are a missing id-token: write permission, which makes the action itself fail, and running node in a different job from the credentials step, where the variables do not exist.
Other CI systems follow the same idea: GitLab and Bitbucket support OIDC roles too, and as a last resort, stored secrets exposed as the standard AWS_* variables work everywhere.
On Lambda, ECS, EKS and EC2: it should just work
Inside AWS, credentials come from a role, automatically. When this error appears there, something is overriding or blocking that:
- Lambda: the execution role's credentials are provided as environment variables. If you see this error in Lambda, your code is almost certainly passing its own
credentials(often empty values from a missing config) or aprofilethat does not exist in Lambda. Remove those and let the default chain work. If instead you see an access denied error, the role exists but lacks permissions. - ECS: set a task role on the task definition (not just the task execution role, which is for pulling images and writing logs). Without a task role, your code has no credentials from step 7.
- EKS: use IAM roles for service accounts or EKS Pod Identity, which provide the web identity token or container credentials the SDK reads. A pod without either falls through to the node's metadata, which is often blocked by the hop limit.
- EC2: attach an instance profile (IAM role) to the instance. Check from the instance:
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/should print a role name (with IMDSv2 required, fetch a token first). No role name means no role attached.
On any of these, hard-coded keys in environment variables take priority over the role (step 1 beats steps 7 and 8). Remove stray AWS_ACCESS_KEY_ID variables from Lambda configuration or task definitions; otherwise you are using whoever's keys those are, not the role you set up.
In the browser (React, Vue, plain JavaScript)
In a browser there is no default chain: no files, no metadata, no environment variables. The SDK cannot find credentials on its own, by design, so calling AWS from browser code without supplying credentials always produces this error. The standard solutions:
- Amazon Cognito identity pools:
fromCognitoIdentityPoolfrom@aws-sdk/credential-providersexchanges a signed-in (or guest) user for temporary, tightly scoped AWS credentials. - A backend in between: often better, the browser calls your API, and your server (with a role) calls AWS.
- Presigned URLs for S3 uploads and downloads: your backend creates a short-lived URL, and the browser uploads directly without any AWS credentials.
Putting access keys into front-end code, even in an environment variable at build time, publishes them to every visitor. Frameworks like Next.js run some code on the server and some in the browser; AWS calls belong in server code, where environment variables or a role are available.
With LocalStack and other local AWS emulators
LocalStack accepts any credentials, but the SDK still needs some to sign requests, so a fresh machine with no AWS setup fails before the request is even sent. Set dummy values:
const s3 = new S3Client({
region: "us-east-1",
endpoint: "http://localhost:4566",
forcePathStyle: true,
credentials: { accessKeyId: "test", secretAccessKey: "test" },
});Keep the explicit credentials only in local and test configuration, so production uses the real default chain. The same applies to DynamoDB Local and other emulators.
If you would rather not change code, set the dummy values as environment variables for the local run only: AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_REGION=us-east-1 node app.mjs. The default chain finds them at step 1, and the endpoint setting points requests at the emulator. In a Docker Compose file for local development, the same three variables go under the app service's environment, next to the emulator's container name as the endpoint host.
In serverless frameworks, SDK wrappers and AI coding tools
Many tools are Node.js programs using this same SDK, so they fail with this exact message when they cannot find credentials:
- Serverless Framework, AWS CDK, Amplify CLI: they read the same profiles and environment variables. Pass
--profileor setAWS_PROFILE, and refresh SSO logins. - AI coding assistants and agents that call Amazon Bedrock: when configured to use Bedrock, they authenticate with the standard AWS chain, so "could not load credentials" means the profile or SSO login they run with is missing or expired. Set
AWS_PROFILEandAWS_REGIONin the environment the tool starts from, runaws sso login, and restart the tool so it picks them up. - Apps run by a process manager (PM2, systemd, a Windows service): they do not inherit your terminal's variables. Put the variables in the service's own configuration.
Every cause, by environment
| Where it runs | Most likely cause | Fix |
|---|---|---|
| Laptop | Profile not selected, or SSO login expired | AWS_PROFILE; aws sso login |
| Laptop, via sudo or a service | Different user, different home folder | Run as your user, or set AWS_CONFIG_FILE |
| Docker locally | No files or variables inside the container | -e AWS_* or mount ~/.aws:ro |
| Docker on EC2 | IMDSv2 hop limit 1 | Hop limit 2 |
| GitHub Actions | No credentials step, or missing id-token: write | configure-aws-credentials with OIDC |
| Lambda | Code overriding the role with empty credentials or a profile | Remove the override |
| ECS | No task role | Add a task role to the task definition |
| EKS | No IRSA or Pod Identity | Associate a role with the service account |
| EC2 | No instance profile | Attach an IAM role to the instance |
| Browser | No default chain exists | Cognito identity pool, a backend, or presigned URLs |
| LocalStack | No credentials to sign with | Dummy keys in local config |
| IDE run or debug | IDE does not see your shell's variables | Set variables in the run configuration |
Setting credentials explicitly in code (when you must)
Usually the default chain is the right answer. When you need to choose a source deliberately, for example a specific profile in a tool that serves several accounts, the @aws-sdk/credential-providers package offers each source on its own:
import { S3Client } from "@aws-sdk/client-s3";
import { fromIni, fromSSO, fromEnv } from "@aws-sdk/credential-providers";
const s3Profile = new S3Client({ region: "us-east-1", credentials: fromIni({ profile: "shop" }) });
const s3Sso = new S3Client({ region: "us-east-1", credentials: fromSSO({ profile: "shop-sso" }) });
const s3Env = new S3Client({ region: "us-east-1", credentials: fromEnv() });Choosing one provider means the others are skipped, so the same code will no longer work on Lambda or EC2 without changes. Keep explicit providers to tools and scripts that really need them, and let applications use the default chain so they run anywhere with the right role.
A good pattern for internal tools is to make the profile a setting rather than a constant, so the same script runs against test or production without edits and falls back to the default chain when no profile is given:
import { S3Client } from "@aws-sdk/client-s3";
import { fromIni } from "@aws-sdk/credential-providers";
const profile = process.env.SHOP_PROFILE; // e.g. SHOP_PROFILE=shop-prod node report.mjs
const s3 = new S3Client({
region: process.env.AWS_REGION || "us-east-1",
...(profile ? { credentials: fromIni({ profile }) } : {}),
});What to avoid is the literal form, credentials: { accessKeyId: "AKIA...", secretAccessKey: "..." } typed into source code. It "fixes" the error instantly and turns into a leaked key the first time the file is committed, shared or pasted into a support chat.
Assuming a role from Node.js
Many setups use one identity to sign in and then assume a role in another account. There are two clean ways to do it in SDK v3.
In the config file, so the default chain handles it everywhere:
[profile shop-prod] role_arn = arn:aws:iam::444455556666:role/ShopUploader source_profile = shop region = us-east-1
With AWS_PROFILE=shop-prod, the SDK signs in with the shop profile, assumes the role, and refreshes the role's credentials as they expire. If the source profile itself is missing or expired, the whole chain fails with this error, so check the source first.
In code, when the role depends on the request (for example, one role per customer account):
import { fromTemporaryCredentials } from "@aws-sdk/credential-providers";
import { S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
region: "us-east-1",
credentials: fromTemporaryCredentials({
params: { RoleArn: "arn:aws:iam::444455556666:role/ShopUploader", RoleSessionName: "nightly-upload" },
}),
});The base credentials for the assume-role call still come from the default chain, so the original problem must be solved first: assuming a role does not create credentials out of nothing. If the assume step fails with access denied instead, the role's trust policy does not allow your base identity.
Long-running apps and credentials that expire
A server that runs for days needs credentials that renew themselves. Sources that refresh automatically: SSO profiles (while the login lasts), assumed roles from a profile or fromTemporaryCredentials, and the ECS, EKS and EC2 role providers. Sources that do not: temporary keys pasted into environment variables. Those work until they expire, typically within hours, and then every call fails with an expired-token error until someone restarts the app with new keys.
So if your error appears after an app has run happily for a while, look for temporary credentials in environment variables and replace them with a role or profile that refreshes. Our expired token guide explains session lifetimes in more detail.
Moving credential code from SDK v2 to v3
A lot of "could not load credentials" reports come from projects in the middle of moving off version 2 of the SDK for JavaScript (the aws-sdk package), which reached end of support on September 8, 2025. Version 2 had its own message for the same problem, so if you see this one, the code is still on v2:
CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
Three things change in v3, and each one can produce the error during a migration:
- There is no global configuration. v2 code often set
AWS.config.credentialsor calledAWS.config.update({...})once at startup and every client inherited it. v3 has noAWS.config: each client gets its owncredentialsandregion, or falls back to the default chain. Code that was migrated client by client but still sets credentials on a global object that v3 never reads ends up with clients that look nowhere special and find nothing. - Credentials are providers, not objects. In v3,
credentialsis usually a function that the client calls when it needs keys, and the providers cache and refresh by themselves. Passing a v2 credentials object instance into a v3 client does not work. - The config file is always read.
AWS_SDK_LOAD_CONFIGis gone; v3 reads~/.aws/configon its own, so settings there (a profile's role, SSO settings, Region) now apply to code that v2 ran without them. A profile name that exists only in the config file, which v2 could not see without that variable, now works.
The v2 credential classes map to v3 provider functions in @aws-sdk/credential-providers:
| SDK v2 (aws-sdk) | SDK v3 (@aws-sdk/credential-providers) |
|---|---|
new AWS.SharedIniFileCredentials({ profile }) | fromIni({ profile }) |
new AWS.EnvironmentCredentials("AWS") | fromEnv() |
new AWS.SsoCredentials({ profile }) | fromSSO({ profile }) |
new AWS.ProcessCredentials({ profile }) | fromProcess({ profile }) |
new AWS.ChainableTemporaryCredentials({ params }) | fromTemporaryCredentials({ params }) |
new AWS.TokenFileWebIdentityCredentials() | fromTokenFile() |
new AWS.ECSCredentials() | fromContainerMetadata() |
new AWS.EC2MetadataCredentials() | fromInstanceMetadata() |
new AWS.CognitoIdentityCredentials({...}) | fromCognitoIdentityPool({...}) |
new AWS.CredentialProviderChain() (the default) | fromNodeProviderChain(), or simply leave credentials out |
A typical before and after for a script that used a named profile:
// v2
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-east-1", credentials: new AWS.SharedIniFileCredentials({ profile: "shop" }) });
const s3 = new AWS.S3();
// v3
import { S3Client } from "@aws-sdk/client-s3";
import { fromIni } from "@aws-sdk/credential-providers";
const s3 = new S3Client({ region: "us-east-1", credentials: fromIni({ profile: "shop" }) });The simplest migration is often to delete the credential code altogether and let the v3 default chain do its job, setting AWS_PROFILE on your laptop and relying on roles in AWS. Less code means fewer places for credentials to go missing.
"Region is missing": the error that often comes next
Fix the credentials and many people immediately hit the next v3 message: "Region is missing". Credentials and Region are separate settings, and v3 refuses to guess a Region. It looks for one in this order: the region you pass to the client, the AWS_REGION environment variable, then the region line of the active profile in ~/.aws/config. On Lambda and in most AWS compute, AWS_REGION is set for you, which is why the same code works there and fails on a laptop.
# any one of these is enough export AWS_REGION=us-east-1 # Mac / Linux shell $env:AWS_REGION = "us-east-1" # PowerShell aws configure set region us-east-1 --profile shop # saved in the profile
One trap: the AWS CLI also reads AWS_DEFAULT_REGION, so machines set up for the CLI often have only that variable, and the JavaScript SDK v3 does not use it. The CLI works and the Node.js app does not. Set AWS_REGION as well, or put the Region in code, and the error goes away.
Related error messages and what each one means
| Message | What it means |
|---|---|
| Could not load credentials from any providers | v3: every source in the chain came back empty |
| Missing credentials in config | The same problem in SDK v2 |
| Unable to find environment variable credentials | You chose fromEnv(), and AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY are not set in this process |
| The SSO session associated with this profile has expired or is otherwise invalid | Run aws sso login --profile NAME again |
| connect ETIMEDOUT / EHOSTUNREACH 169.254.169.254 | The chain reached its last step, EC2 instance metadata, on a machine or container that cannot reach it |
| ExpiredToken / The security token included in the request is expired | Credentials loaded but are temporary and out of date |
| InvalidClientTokenId | Credentials loaded, but AWS does not recognize the access key |
| AccessDenied / not authorized to perform | Credentials work; the identity lacks permission |
| Region is missing | Credentials may be fine; no Region was configured (previous section) |
The table reads top to bottom as progress: the first two mean nothing was found, the middle rows mean something was found but is unusable, and the last rows mean credentials work and the problem has moved on. An unrecognized key has its own guide: InvalidClientTokenId explained.
Unit tests that need no AWS credentials
Tests that call real AWS services need real credentials, which is why CI pipelines so often fail with this error on the test step. For unit tests, the cleaner answer is to never reach AWS at all. The community library aws-sdk-client-mock replaces a v3 client's send method, so commands return the values you choose and the credential chain is never consulted:
// npm install --save-dev aws-sdk-client-mock
import { mockClient } from "aws-sdk-client-mock";
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
const s3Mock = mockClient(S3Client);
s3Mock.on(GetObjectCommand).resolves({ ContentLength: 42 });
// code under test that does new S3Client({}).send(new GetObjectCommand(...))
// now gets { ContentLength: 42 } with no network and no credentialsFor integration tests against an emulator such as LocalStack, pass any fixed values (the emulator does not check them) together with the emulator's endpoint, as the LocalStack section shows. Keep real AWS calls for a small set of end-to-end tests that run with a CI role through OIDC, never with long-lived keys stored in the repository's secrets if you can avoid it.
Servers and hosts outside AWS
Code running on your own servers, on another cloud or on a hosting platform has no instance role to fall back on, so the chain ends without credentials unless you give it one. In order of preference:
- Web identity federation (OIDC): if the platform can issue identity tokens (GitHub Actions, GitLab, Kubernetes clusters and several hosting platforms can), create an IAM OIDC identity provider and a role that trusts it. The SDK exchanges the token for short-lived credentials through
fromTokenFile()orfromWebToken(), and there are no keys to leak or rotate. - IAM Roles Anywhere: for your own servers with certificates from your own certificate authority. A small helper program obtains temporary credentials, and the SDK reads them through a
credential_processline in the profile. - Access keys from the platform's secret store: set
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYas encrypted environment variables in the host's settings, scoped to one IAM user with the minimum permissions, and rotate them on a schedule.
Whichever you choose, confirm it with the test script from earlier, run on that host. A deployment that works on your laptop proves only that your laptop has credentials.
A .env file that is never loaded
One of the most common causes on a developer's laptop has nothing to do with AWS: the keys are in a .env file, and nothing ever reads it. Node.js does not load .env files by itself. Frameworks do it for you (Next.js, Vite and others read .env files at startup), so the same keys work inside the app and are missing when you run a plain script with node script.mjs from the same folder.
Three ways to load the file for plain Node.js:
# Node.js 20.6 and later: built in node --env-file=.env script.mjs # any Node version: the dotenv package, first line of your entry file import "dotenv/config"; # or set the variables in the shell for one run (Mac / Linux) AWS_PROFILE=shop node script.mjs
In Next.js there is a second trap. Variables whose names start with NEXT_PUBLIC_ are copied into the JavaScript sent to the browser. Never give AWS keys that prefix: server code (API routes, server actions, route handlers) can read plain AWS_ACCESS_KEY_ID, and the browser should get only the results, or short-lived credentials from Cognito as the browser section explains. If an AWS call works in a server route and fails in a client component with this error, that is the design working as intended: move the call to the server.
New to the SDK: what it is and which packages you need
If you landed here from an error in someone else's project, a little background helps. The AWS SDK for JavaScript is the library Node.js and browser code uses to call AWS services. Version 3, the current one, is split into small packages, one per service, so an app installs only what it uses:
npm install @aws-sdk/client-s3 # S3 npm install @aws-sdk/client-dynamodb # DynamoDB npm install @aws-sdk/credential-providers # only if you choose credential sources yourself
Every client package already contains the default credential chain, so most apps never install the credential-providers package at all. Each call is a command object sent through a client, such as client.send(new ListBucketsCommand({})), and the first send is when the chain runs; that is why the error appears at the first AWS call rather than when the client is created. Keep all @aws-sdk/* packages on matching versions (update them together), because mismatched versions in one project cause odd failures that can look like credential problems.
The fix, step by step
- Run the test script where the failure happens, to confirm the environment, not your code, is missing credentials.
- Decide which source should provide them here: profile or SSO (laptop), variables or mount (Docker), OIDC (CI), role (AWS compute), Cognito or a backend (browser).
- Fix that one source using the section above.
- Remove stray overrides: hard-coded
credentials, unusedAWS_ACCESS_KEY_IDvariables, wrongprofilesettings. - Re-run the test, then your application.
- If the error becomes "access denied," credentials now load, and the remaining work is IAM permissions for the identity that the test printed.
Two habits stop the error coming back. First, run the test script as part of every new environment's setup (a new laptop, a new CI pipeline, a new container image) before anyone runs the real application there, so a missing source shows up in a one-line check instead of a stack trace in production. Second, write down which source each environment is supposed to use, in the project's README: "laptops use the shop-dev SSO profile, CI uses the OIDC role, production uses the task role". Most repeats of this error happen when someone new joins and guesses.
Frequently asked questions
What does "Could not load credentials from any providers" mean?
The AWS SDK for JavaScript v3 checked environment variables, SSO, shared config files, credential processes, web identity tokens and the ECS and EC2 metadata services, and found no credentials.
How do I fix CredentialsProviderError in Node.js locally?
Set AWS_PROFILE to an existing profile, or set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. For SSO profiles, run aws sso login --profile NAME.
Why does it work with the AWS CLI but not in Node.js?
Usually the two run with different environments: a different AWS_PROFILE, user, or terminal. Compare them, and run a credential test in the same place the app runs.
How do I fix the error in Docker?
Pass AWS_* environment variables, mount ~/.aws read-only and set AWS_PROFILE, or on EC2 raise the IMDSv2 hop limit to 2 so the container can reach the instance role.
How do I fix it in GitHub Actions?
Add aws-actions/configure-aws-credentials with role-to-assume and aws-region, and give the workflow id-token: write permission for OIDC.
Why do I get this error in AWS Lambda?
Lambda provides role credentials automatically, so the code is probably overriding them with empty credentials or a missing profile. Remove the override.
Do I need AWS_SDK_LOAD_CONFIG in SDK v3?
No. Version 3 reads ~/.aws/config automatically; AWS_SDK_LOAD_CONFIG was only for version 2.
Why does the error appear in the browser?
Browsers have no default credential chain. Use Amazon Cognito identity pools, call a backend, or use presigned URLs.
How do I use LocalStack without this error?
Give the client dummy credentials such as accessKeyId "test" and secretAccessKey "test", along with the LocalStack endpoint.
How do I check which credentials the SDK is using?
Call fromNodeProviderChain() from @aws-sdk/credential-providers, then STS GetCallerIdentity, which prints the account and ARN.
What is the order of the SDK v3 credential provider chain?
Environment variables, SSO, shared config and credentials files, login credentials, credential process, web identity token file, ECS container credentials, then EC2 instance metadata.
Why does my ECS task get this error?
The task definition has no task role. The task execution role is only for pulling images and logs; add a task role for your code.
Can an expired SSO login cause this error?
Yes. When the SSO step fails and no other source has credentials, the chain ends with this error. Run aws sso login.
What is the difference between this error and access denied?
This error means no credentials were found. Access denied means credentials were found but lack permission for the action.
Why does an AI coding tool show this error with Bedrock?
It uses the standard AWS credential chain. Set AWS_PROFILE and AWS_REGION where the tool starts, refresh your SSO login, and restart the tool.
What does "Missing credentials in config" mean?
It is SDK v2's version of the same error: no source provided credentials. If you see it, the code still uses the aws-sdk v2 package, which reached end of support on September 8, 2025; move to v3 and the default chain.
How do I migrate AWS credentials code from SDK v2 to v3?
Replace v2 classes with v3 provider functions from @aws-sdk/credential-providers (SharedIniFileCredentials to fromIni, EnvironmentCredentials to fromEnv, and so on), set credentials and region per client instead of on AWS.config, or remove the credential code and use the default chain.
How do I fix "Region is missing" in SDK v3?
Set a Region: pass region to the client, set AWS_REGION, or add region to the profile in ~/.aws/config. It is a separate setting from credentials.
Why does my .env file not fix the error?
Plain Node.js does not read .env files. Load it with node --env-file=.env (Node 20.6+) or the dotenv package; frameworks like Next.js load it for you, but only for server code.
How do I test AWS SDK v3 code without credentials?
Mock the client with aws-sdk-client-mock so send returns fixed values and no credentials are needed, or point integration tests at an emulator with fixed dummy keys.
Is it safe to put AWS keys in a Dockerfile or front-end code?
No. Anyone with the image or the page gets the keys. Use roles, OIDC, mounted files for local work, or a backend.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • Security – Specialty (SCS-C03) • CloudOps Engineer – Associate (SOA-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. An application on EC2 needs to call S3 without storing access keys. What is the recommended approach?
Attach an IAM role to the instance through an instance profile; the SDK gets temporary credentials from the metadata service.
2. Code in an ECS task cannot find credentials, although the task runs fine. What is missing?
A task role on the task definition (the task execution role only covers pulling images and logs).
3. A GitHub Actions workflow must deploy to AWS without long-term access keys. What do you use?
An IAM OIDC identity provider for GitHub and a role assumed with web identity (for example via configure-aws-credentials).
4. Containers on an EC2 instance with IMDSv2 required cannot reach instance role credentials. Which setting fixes it?
Increase the metadata response hop limit to 2.
5. A browser application must upload files directly to S3 without exposing AWS credentials. What do you use?
Presigned URLs created by a backend (or temporary credentials from an Amazon Cognito identity pool).
6. Developers need short-lived credentials for local SDK and CLI use, managed centrally. Which service?
AWS IAM Identity Center (SSO).
7. Which credential source does the AWS SDK check first in its default chain?
Environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
The upload script now runs in three places, each with the right kind of key: Ethan's SSO profile on his laptop, an IAM role passed through the hop-limit fix on the back-room PC's EC2 test machine, and an OIDC role in GitHub Actions. None of them stores an access key anywhere. Jake asked why one script needed three different answers. "Same script, three different houses," Ethan said. "Each one keeps its keys in a different drawer."
📌 If you keep one line from this page
"Could not load credentials from any providers" means no source in the SDK's chain had credentials: set AWS_PROFILE and refresh SSO locally, pass variables or fix the hop limit in Docker, use OIDC in CI, attach a role on AWS compute, and never rely on a default chain in the browser.
Test with fromNodeProviderChain + GetCallerIdentity · v3 needs no AWS_SDK_LOAD_CONFIG · ECS needs a task role · LocalStack needs dummy keys.
Revision note. Written October 19, 2026, for the AWS SDK for JavaScript v3. The error is always the same sentence; the missing key is always in a different drawer.