-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use SDK v3 with dynamodb local - nodejs v18 #4294
Comments
Hi @Berger92, thanks for opening this issue. Could you please try specifying the endpoint as follow: const client = new DynamoDBClient({
endpoint: {
hostname: 'localhost',
port: 8000,
path: '',
protocol: 'http:',
}
}); Your example code should look as follow: import {DynamoDBClient, ListTablesCommand} from '@aws-sdk/client-dynamodb';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
const client = new DynamoDBClient({
endpoint: {
hostname: 'localhost',
port: 8000,
path: '',
protocol: 'http:',
}
});
const ddbDocClient = DynamoDBDocument.from(client);
(async () => {
const result = await ddbDocClient.send(new ListTablesCommand({}));
console.log(result);
})(); Let me know if that works. Thanks! |
Hi @yenfryherrerafeliz 👋
|
@yenfryherrerafeliz Just one additional piece of information that might help. I am using DynamoDB Local in a Docker container, latest version. |
@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! |
Hi @Berger92, sorry for the delay in getting back. After doing some researches I found that the issue that you are getting may be due to a factor out of the SDK itself. According with the error that you are getting, seems like the connection to the specified host and port is being refused, and this could be due to different situations, maybe the specified port is not open to be accessible, out of the container, and actually did you make sure you are running the image with the right port mapping?, because it seems to be a networking issue. Thanks! |
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. |
Any updates? Having the same issue using the VSCode debugger. |
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 |
I encountered this issue as well. It ended up being a combination of a couple issues (unrelated to the AWS SDK):
Changing |
I concur using using this without issue:
|
Same problem with SQS part and use the same resolution : with |
Switching to
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
|
Thanks, I had the same issue and your solution worked for me as well! :) |
I'm facing the same issue. Changing
My error code is a bit different though.
|
This little 'subtle' change has cost me so much time 😭 Instead of ❓ ✅ const client = new DynamoDBClient({
endpoint: `http://0.0.0.0:8000`
}); ProTip: You can even use (Note: When binding services to |
The soultion proposed by @justsml isn't working for us:
Neither is the |
I can confirm that the following is working for me at least, using DynamoDB Local running from NoSQL Workbench, running on port 8111 (instead of the default 8000).
Things to note:
If you are connecting to Docker and getting ECONNREFUSED, test that the connectivity is working outside of Node.js... you might need to something like one or more of the following:
In short, make sure you try and test connectivity with a tool such as 'nc' (alternatively 'telnet' or PuTTY can be used to test connectivity to any (raw) port without expecting an actual TTY) Some useful diagnostic commands (Linux)
PS. If you're curious as to why connecting to why 0.0.0.0 might work (as someone practiced in the Sockets API I was surprised myself by this), the following has some good discussion and references to RFC5735 section 3. https://unix.stackexchange.com/questions/419880/connecting-to-ip-0-0-0-0-succeeds-how-why |
I was also running into the Error: connect ECONNREFUSED 127.0.0.1:8200 but none of the above seemed to make any difference. When I fired up I tried adding a 2s sleep after starting dynamodb-local before I started querying and it seems to be working. So ultimately I took out the delay and just put in a retry that handles ECONNREFUSED on the first query after starting. This seems to be working fine and seems to take about 2s after launching to be ready. I wonder if the old AWS SDK V2 had some built-in retries for ECONNREFUSED that is not in V3? Otherwise it doesn't make much sense to me that V2 would work fine without any special handling. |
I know this is old, but wanted to point folks here: Which says:
It would look something like (note that
|
i use my local ipv4 like 192.168.0.2 (ifconfig on window)
|
I'm currently encountering this and it appears to be an interaction with the SDK preferring environment variables over the code configurations. my configuration looks like
But when attempting to connect I get the error
Logging my process.env I see
I'm trying to connect locally from a lambda running in SAM against DynamoDB running in a local docker container. Is there any way to override the dynamically constructed endpoint going off the environment variables? As a client I would expect my code to take precedence, not my environment variables, at least if I'm hardcoding a specific endpoint. My environment variables might be being used for something entirely unrelated as that's a global configuration. I can see how this logic would be useful in the AWS environment but right now trying to run locally I'm fairly stuck. |
Just as a test I tried deleting those environment variables in my startup code.
I then got the error
Adding the
I also tried with the endpoint configuration format used in the above thread with both combinations of environment variables but this encountered the same issues as previously described.
It appears the endpoint configuration does not do anything at all? Not sure how it's possible to get the code working as described earlier in this thread. I'm on version |
It appears that there is in fact a way to get past this problem if you lean into the environment variable based way of configuration. Using the service-specific endpoint environment variable More information:
The other documented environment variables like |
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
Observed Behavior
Expected Behavior
The list of local dynamodb tables
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: