AWS SDK for JavaScript v3 cannot find credentials, even for DynamoDB Local
Could not load credentials from any providersShort answer
The SDK walked its default credential provider chain and found nothing. Supply credentials from any one source: environment variables, the shared credentials file, or an SSO login. For DynamoDB Local the values need not be real, but the SDK still needs some access key and a Region in its configuration.
Fix it fast
1Find out which cause you have
List which credential sources the process can see: the environment variables and the profile the SDK will use.
env | grep '^AWS_' ls -l ~/.aws/credentials ~/.aws/config2Match what you see, then jump to its fix
- 1
env shows no AWS_ variables and the credentials file is missing.Nothing is set in any source of the default chainFix - 2
The client points at http://localhost:8000 and still fails with this error.DynamoDB Local needs a key and Region in the client configFix - 3
aws configure list works in your terminal, but the failing process is an IDE, a container or a service.A real credentials source exists, but the process cannot see itFix
- 1
What does the error look like?
Could not load credentials from any providersA DynamoDB client pointed at http://localhost:8000 fails with the same message
Cause 1 of 3
Nothing is set in any source of the default chain
1Check
The v3 default chain checks environment variables, then SSO, then the shared config and credentials files, then process, web identity token, container and EC2 instance metadata sources, and stops at the first that returns credentials.
ls -l ~/.aws2Fix
Provide one source. For local work, environment variables are the quickest; the Region is needed as well.
export AWS_ACCESS_KEY_ID=your-access-key-id
export AWS_SECRET_ACCESS_KEY=your-secret-access-key
export AWS_REGION=us-west-23Verify
Start the app from the same shell, because environment variables apply to that session.
node app.jsConfirmed by docs.aws.amazon.com
Cause 2 of 3
DynamoDB Local needs a key and Region in the client config
1Check
AWS documents that the SDKs require an access key value and a Region value in the configuration, and that for DynamoDB Local these do not have to be valid. The local endpoint must also be set on the client.
curl -s http://localhost:8000 | head -c 2002Fix
Pass an endpoint and any placeholder credentials to the client. The access key id may only contain letters and numbers.
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
const client = new DynamoDBClient({
region: 'us-west-2',
endpoint: 'http://localhost:8000',
credentials: { accessKeyId: 'localkey', secretAccessKey: 'localsecret' },
})3Verify
List tables against the local endpoint.
aws dynamodb list-tables --endpoint-url http://localhost:8000Confirmed by docs.aws.amazon.com
Cause 3 of 3
A real credentials source exists, but the process cannot see it
1Check
Environment variables belong to one shell session or process. A container or service does not inherit them, and a different user has a different home folder.
docker exec my-app env | grep '^AWS_'2Fix
Pass the variables into that process, or mount the credentials file, or give the process the role it should use. Avoid mixing sources: AWS warns you can change permissions without noticing.
docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_REGION my-app3Verify
Print the variable names inside the process and restart it.
docker exec my-app env | grep '^AWS_'Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Use short-term credentials such as IAM Identity Center for real accounts, as AWS recommends.
- Keep to one credential source per environment so the chain's order never surprises you.
- Give DynamoDB Local clients an explicit endpoint, a Region and placeholder keys in the test setup only.
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
The AWS SDK in Node.js cannot find any credentials
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2.
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