aws-sdk-js-v3: Cannot use SDK v3 with dynamodb local - nodejs v18

Checkboxes for prior research

Describe the bug

Hi 👋

I’ve seen this issue in the past, but they have all been closed. I am migrating from my app using SDK v2 to SDK v3.

I’m also updating nodejs version to 18, but it doesn’t seem to work.

I’ve tried tinkering with config, adding fake credentials, etc. but I got nowhere.

If I use nodejs 16, it does work.

SDK version number

v3.231.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

18.12.1

Reproduction Steps

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';

const client = new DynamoDBClient({
  endpoint: 'http://localhost:8000'
});
const ddbDocClient = DynamoDBDocument.from(client);

(async () => {
  const result = await client.send(new ListTablesCommand({}));

  // or const result = await ddbDocClient.send(new ListTablesCommand({}));

  console.log(result);
})();

Observed Behavior

Error: connect ECONNREFUSED ::1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 8000,
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Expected Behavior

The list of local dynamodb tables

Possible Solution

No response

Additional Information/Context

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18 (3 by maintainers)

Most upvoted comments

I encountered this issue as well. It ended up being a combination of a couple issues (unrelated to the AWS SDK):

Changing localhost to 127.0.0.1 resolved the issue for me.

Switching to 127.0.0.1 didn’t do the trick for me. What did help though is providing dummy credentials to the dynamo client like this:

    const client = new DynamoDBClient({
        endpoint: `http://localhost:8000`,
        region: 'local',
        credentials: {
            accessKeyId: 'dummy',
            secretAccessKey: 'dummy'
        }
    })

Found the solution here: https://stackoverflow.com/questions/43322536/could-not-load-credentials-from-any-providers-while-using-dynamodb-locally-in

My issue was different though than described in this question. It seemed that SDK simply ignored the endpoint argument in my case, and kept trying to reach out to the real AWS services, I was getting this error:

Could not load credentials from any providers
CredentialsProviderError: Could not load credentials from any providers

Hi @yenfryherrerafeliz . I disagree with you, because as I said in the original post, the docker container works for me perfectly with SDK v3 using Nodejs16. The problem started occurring using Nodejs 18. (In addition, the aws cli also works)

Hi @yenfryherrerafeliz 👋 Thanks for the quick response. I’ve tried it, but I got the same result as before

Error: connect ECONNREFUSED ::1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 8000,
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

@Berger92, thanks for the information. This also helps with my reproduction, since in my local environment “localhost” is being resolved as 127.0.0.1. I will try with this new information and I will get back to you as soon as possible.

Thanks!