aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
"endpoint" configuration parameter is ignored by DynamoDBClient
Describe the bug
Trying to migrate to aws-sdk 3 from aws-sdk 2. We are using endpoint
configuration parameter to have the Dynamo client talk to a local instance of Dynamo for unit tests, but the SDK ignores it, and keeps trying to reach the remote Dynamo, resulting in an error ExpiredToken: The security token included in the request is expired
Your environment
Node 12.20.1, MacOS Catalina
SDK version number
"@aws-sdk/client-dynamodb": "3.16.0"
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
Node 12.20.1
Steps to reproduce
const {DynamoDBClient, BatchWriteItemCommand} = require('@aws-sdk/client-dynamodb');
const {marshall} = require('@aws-sdk/util-dynamodb');
(async () => {
const dynamoClient = new DynamoDBClient({endpoint: "http://localhost:2348"});
const ids = ['1232'];
const params = {
RequestItems: {
'mytable': ids.map((id) => {
return {
DeleteRequest: {
Key: marshall({id}),
},
};
}),
},
};
const command = new BatchWriteItemCommand(params);
await dynamoClient.send(command);
})().catch(e => {
console.log(e, 'error');
})
Observed behavior
AWS SDK client tries to send requests to real Dynamo AWS.
Expected behavior
AWS SDK client should be sending requests to local Dynamo instance.
Hi @IevgenRagulin thanks for opening this issue, is it still an issue with the latest version of the SDK? I was not able to reproduce it.
This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.
I'm facing a similar issue, only with SNS connected to localstack.
I'm setting the right endpoint URL, but looks like it still tries to connect to AWS because of this error: The security token included in the request is invalid
Hi @gornostal, i´m getting the same error on SQS, have you fixed it?
@frannav yes, I fixed it. I think by passing AWS_REGION
env variable to my app container.
I also have this in my config:
const snsConfig: SNSClientConfig = {
region: process.env.AWS_REGION,
endpoint: process.env.NODE_ENV == 'dev' ? 'http://localstack:4566' : null,
};
I forgot what exactly fixed the issue. It was a month ago.
@frannav ah, I remember -- it was an issue related to nestjs dependency injection. I've misconfigured it and it would create an SNSClient
instance without passing the config object in there.
Thanks!
@ajredniwja , I confirm it's still an issue when using the latest sdk (3.85.0). Passing AWS_REGION
as suggested by @gornostal doesn't help in my case.
Revisiting during review meeting. The action item would be to check if endpoint which contains localhost is overridden in any middleware.
@gornostal Our endpoint resolution has changed since this issue was reported in May'21.
Is this issue still reproducible for you?
The HttpRequest is created in serializer.
I logged the contents in buildHttpRpcRequest
before HttpRequest is created, for testing listTables
// node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js
const buildHttpRpcRequest = async (context, headers, path, resolvedHostname, body) => {
// ...
console.log({ contents });
return new protocol_http_1.HttpRequest(contents);
};
And ran the following script:
import { DynamoDB } from "@aws-sdk/client-dynamodb";
const client = new DynamoDB({ endpoint: "http://localhost:2348" });
try {
await client.listTables({});
} catch (err) {
console.log(err);
}
I verified that request attempt is made for localhost, as required by the configuration. The error is thrown on my laptop, as it's not running local DynamoDB instance.
{
contents: {
protocol: 'http:',
hostname: 'localhost',
port: 2348,
method: 'POST',
path: '/',
headers: {
'content-type': 'application/x-amz-json-1.0',
'x-amz-target': 'DynamoDB_20120810.ListTables'
},
body: '{}'
}
}
Error: connect ECONNREFUSED 127.0.0.1:2348
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 2348,
'$metadata': { attempts: 1, totalRetryDelay: 0 }
}
@gornostal Is this issue reproducible for you?
My environment:
- Node:
v16.19.0
- SDK:
@aws-sdk/[email protected]
@trivikr sorry, I can't confirm. I'm not working on that project anymore.
Closing this issue, as it's not reproducible as per testing in https://github.com/aws/aws-sdk-js-v3/issues/2416#issuecomment-1430156717, and original author is not working on the project.
If this issue is reproducible for you, please create a new bug report (recommended), or comment on this issue with a minimal repro.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.