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 4 years ago
  • Reactions: 7
  • Comments: 28 (5 by maintainers)

Most upvoted comments

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

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.

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

@aBurmeseDev that’s absolutely hilariously classic AWS SDK team. here’s a thought - start with the OP that offered a reproduction, and then ask people whose variants aren’t solved by that resolution to open issues.

closing the issue wholesale because the sdk is so broken in this aspect, as to produce so many variants on an issue, without addressing the original issue provided isn’t just lazy, it’s being a bad steward of open source.

This little ‘subtle’ change has cost me so much time 😭

Instead of 127.0.0.1, 👎 Use 0.0.0.0 👍

❓127.0.0.* will always be exclusively local - making some things more difficult. (e.g. seamless interop with docker, clear ipv4 behavior)

✅ 0.0.0.0 will allow both access and binding (to the host) using IPv4.

const client = new DynamoDBClient({
  endpoint: `http://0.0.0.0:8000`
});

ProTip: You can even use http://0.0.0.0:8000 in your browser for local web sites. 🚀

(Note: When binding services to 0.0.0.0 it could make them accessible to anyone on your WiFi/local network. Use best practices, judgement, firewall, docker networks, safe WiFi, etc.)

This may be resolved when #4466 is fixed.

In my case I’m not using docker, but I was getting this same error because I was sending the dynamodb command too fast after spinning up a local dynamodb instance. I found that if I put a 1 second pause in before the ddbDocClient.send(...), my problem went away.

@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!