The AWS SDK in Node.js cannot find any credentials
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1Short answer
The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2. This error means every step came back empty. Find which source you meant to use, then set its variables or file correctly for the process that runs Node.js.
Fix it fast
1Find out which cause you have
Check from the same shell and user that runs Node.js which AWS variables are set and whether the shared credentials file exists.
env | grep '^AWS_' | sed 's/=.*/=<set>/' ls -l ~/.aws/credentials ~/.aws/config2Match what you see, then jump to its fix
- 1
The keys work in your terminal but not under PM2, systemd, Docker or a LambdaThe process does not see the environment variables you setFix - 2
No file at ~/.aws/credentials for the user running Node.js, or your keys sit under a named profileThe shared credentials file is missing, in the wrong place or under another profileFix - 3
Works on your laptop, fails on a server, container or functionThe code runs somewhere that should use a role, and no role source is availableFix
- 1
What does the error look like?
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
Cause 1 of 3
The process does not see the environment variables you set
1Check
Environment variables override values from the shared files, and they exist only for the shell, container or service that has them. List the variable names the process actually has.
env | grep '^AWS_' | sed 's/=.*/=<set>/'2Fix
Set the variables where the process starts: in the service unit, the container env, or the Lambda configuration.
export AWS_ACCESS_KEY_ID=<your-key-id>
export AWS_SECRET_ACCESS_KEY=<your-secret>
export AWS_REGION=us-west-23Verify
Start Node.js from that same shell and call the service.
node -e "console.log(Boolean(process.env.AWS_ACCESS_KEY_ID))"Confirmed by docs.aws.amazon.com
Cause 2 of 3
The shared credentials file is missing, in the wrong place or under another profile
1Check
The SDK reads ~/.aws/credentials (on Windows C:\Users\USER_NAME\.aws\credentials). It uses the [default] profile unless the AWS_PROFILE environment variable names another.
cat ~/.aws/credentials | sed 's/=.*/= <hidden>/'
echo "profile: ${AWS_PROFILE:-default}"2Fix
Put the keys under [default], or set AWS_PROFILE to the profile that has them.
# ~/.aws/credentials
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
# or choose a profile
export AWS_PROFILE=work-account3Verify
Start Node.js again from that shell.
node script.jsConfirmed by docs.aws.amazon.com
Cause 3 of 3
The code runs somewhere that should use a role, and no role source is available
1Check
The v3 default chain also tries IAM Identity Center, web identity, ECS container credentials and the EC2 instance profile, in that documented order. If none is attached to the server, the chain ends empty.
echo "$AWS_PROFILE $AWS_ROLE_ARN"2Fix
Attach an IAM role to the instance, task or function, and do not pass credentials in code. Leave the client without a credentials option so the default chain runs.
import { S3Client } from "@aws-sdk/client-s3";
const client = new S3Client({ region: "us-west-2" });3Verify
Call one cheap API from the server.
node -e "import('@aws-sdk/client-s3').then(m=>new m.S3Client({region:'us-west-2'}).send(new m.ListBucketsCommand({}))).then(r=>console.log(r.Buckets.length))"Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Prefer roles and short-term credentials over long-lived keys in files.
- Do not mix sources: a key in code, one in env and one in a file makes it unclear which wins.
- Log the profile name and region at start-up (never the keys).
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
AWS SDK for JavaScript v3 cannot find credentials, even for DynamoDB Local
A DynamoDB client pointed at http://localhost:8000 fails with the same message
The SDK walked its default credential provider chain and found nothing.
3 causes, each with a fixBack end
AWS SDK says the security token included in the request is invalid
The security token included in the request is invalid
The call reached AWS but the credentials it carried were refused.
3 causes, each with a fixBack end
Amazon Cognito says the user pool client does not exist
ResourceNotFoundException (HTTP status code 400) returned by InitiateAuth
Cognito looks the app client ID up inside the Region you call.
3 causes, each with a fixBack end
Node.js S3 client cannot resolve my-bucket.localhost on LocalStack
Error: getaddrinfo ENOTFOUND bucketname.localhost
The SDK puts the bucket name in the hostname (virtual-hosted style), so it looks up my-bucket.localhost, which does not resolve.
3 causes, each with a fixBack end
S3 says Access Denied when my Node.js code reads or writes an object
Access Denied
S3 answers AccessDenied when no policy allows the exact action on the exact resource, when something denies it, or when the SDK signs with a different identity than you think.
5 causes, each with a fixBack end
API Gateway gives up on a slow Lambda or Node.js backend
$context.integrationErrorMessage in the access log shows the integration error
API Gateway stops waiting for the backend at its integration timeout: 29 seconds by default on REST APIs, a fixed 30 seconds on HTTP APIs.
4 causes, each with a fix