CredentialsProviderError: Could not load credentials from any providers
Node.js · updated 2026-11-04
Thrown by the AWS SDK for JavaScript v3 on the first call that needs to sign a request, after its default chain finds nothing: environment variables, SSO, a web identity token file, ~/.aws/credentials and ~/.aws/config, a credential process, then the container or EC2 instance metadata endpoint. It usually works on a laptop (a local profile) and fails in a container or CI.
CredentialsProviderError: Could not load credentials from any providers
at /app/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js:135:13
at /app/node_modules/@smithy/property-provider/dist-cjs/index.js:97:33
at async coalesceProvider (/app/node_modules/@smithy/core/dist-cjs/index.js:1192:18)
at async S3Client.send (/app/node_modules/@smithy/smithy-client/dist-cjs/index.js:173:13)Quick fix
In production, give the workload an IAM role: an ECS task role, an EKS service account role, or an EC2 instance profile; the SDK picks it up with no code change. For other hosts, set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (plus AWS_REGION) in the environment that starts the process. If AWS_PROFILE is set, either remove it or make sure that profile exists on the machine: with AWS_PROFILE set the SDK skips the environment keys.
- Check where the code runs (container, Lambda, EC2, another cloud, CI) and which credential source is meant to apply there.
- AWS compute: attach an IAM role to the task, pod service account or instance instead of shipping keys.
- Elsewhere: set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION in the deploy environment (a secret manager, not the image).
- Unset AWS_PROFILE on servers unless ~/.aws/config with that profile is present: it makes the SDK skip the env keys.
- Docker on EC2 with IMDSv2: raise the instance metadata hop limit to 2 so containers can reach the instance role.
import { S3Client } from '@aws-sdk/client-s3';
// No credentials in code: the SDK's default chain finds the role or env keys.
export const s3 = new S3Client({ region: process.env.AWS_REGION });
// Fail at startup with a clear message instead of on the first request
if (!process.env.AWS_REGION) throw new Error('AWS_REGION is not set');Why it happens
Keys only on the developer machine
Locally the SDK reads ~/.aws/credentials; the container or CI runner has no such file and no env keys.
AWS_PROFILE set on the server
When AWS_PROFILE is set, the default chain skips the environment-variable keys and looks for that profile in ~/.aws files, which usually don't exist on a server.
No role attached
An ECS task without a task role, a pod without an IRSA service account, or an EC2 instance without an instance profile has nothing for the metadata provider to return.
Instance metadata unreachable
Containers on EC2 with IMDSv2 and the default hop limit of 1 cannot reach the metadata endpoint, so the instance role is never found.
Other fixes
- Prefer roles over long-lived keys: they rotate automatically and there is nothing to leak.
- For local development, aws sso login with a named profile keeps keys off disk.
Same error, other wording
- CredentialsProviderError: AWS_PROFILE is set, skipping fromEnv provider.
- Error: Region is missing
- ExpiredToken: The security token included in the request is expired
Let your coding agent catch the next one
Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:
> Find the "Could not load credentials from any providers" errors in production, tell me where the code runs and which credential source it should use there, and fix the deployment config (role or env) without putting keys in the code.
Related errors
- Error: connect ETIMEDOUT 10.0.4.12:5432
- Error: getaddrinfo ENOTFOUND api.example.com
- TypeError: fetch failed
More in Memory, async and the process
- [UnhandledPromiseRejection: This error originated either by throwing inside of an async...Node.js
- FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memoryNode.js
- RangeError: Maximum call stack size exceededNode.js
- RecursionError: maximum recursion depth exceededPython
- RuntimeError: Event loop is closedPython
- RuntimeWarning: coroutine 'fetch_user' was never awaitedPython
- Error: listen EADDRINUSE: address already in use :::3000Node.js
- OSError: [Errno 98] Address already in usePython
- Error: error:0308010C:digital envelope routines::unsupportedNode.js
- MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error...Node.js
- Error: ENOENT: no such file or directory, open '/app/config.json'Node.js
- Error: EACCES: permission denied, open '/app/data/cache.json'Node.js
- Error: EMFILE: too many open files, open '/app/uploads/0412.jpg'Node.js
- PermissionError: [Errno 13] Permission denied: '/app/data/report.csv'Python
- botocore.exceptions.NoCredentialsError: Unable to locate credentialsPython
- django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.Python
References: AWS docs: setting credentials in Node.js (SDK v3), AWS SDK v3 source: default credential provider chain, AWS docs: configure instance metadata options (hop limit)