Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

AWS SDK for JavaScript v3 cannot find credentials, even for DynamoDB Local

ErrorCould not load credentials from any providers

Short 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.

  • Applies to AWS SDK for JavaScript v3, Node.js 22, DynamoDB Local
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/config
  2. 2Match what you see, then jump to its fix

    1. 1env shows no AWS_ variables and the credentials file is missing.Nothing is set in any source of the default chainFix
    2. 2The client points at http://localhost:8000 and still fails with this error.DynamoDB Local needs a key and Region in the client configFix
    3. 3aws 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

What does the error look like?

  • Could not load credentials from any providers
  • A 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 ~/.aws

2Fix

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-2

3Verify

Start the app from the same shell, because environment variables apply to that session.

node app.js

Confirmed by docs.aws.amazon.com

Did this fix it?

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 200

2Fix

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:8000

Confirmed by docs.aws.amazon.com

Did this fix it?

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-app

3Verify

Print the variable names inside the process and restart it.

docker exec my-app env | grep '^AWS_'

Confirmed by docs.aws.amazon.com

Did this fix it?

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:

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 fix

Back 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.