-
Notifications
You must be signed in to change notification settings - Fork 594
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
Custom middleware to mutate input does not work #6743
Comments
Hi @alfaproject - thanks for reaching out. Could you try this simpler version of code modifying import { DynamoDB } from "@aws-sdk/client-dynamodb";
const ddb = new DynamoDB();
ddb.middlewareStack.add(
(next) => (args) => {
args.input = {
...args.input,
ReturnConsumedCapacity: "TOTAL",
};
return next(args);
},
{
name: "logConsumedCapacityMiddleware",
step: "initialize",
override: true,
}
);
await ddb.putItem({
TableName: "test",
Item: {
id: {
S: "1",
},
value: {
S: "hello",
},
},
});
const item = await ddb.getItem({
TableName: "test",
Key: {
id: {
S: "1",
},
},
});
console.log(item); |
Hello, thank you for your support, but that doesn't work either. I suspect the problem is from // DocumentClient factory which is the one we're really using in our application
export function dynamoDbDocumentClient() {
const ddb = new DynamoDBClient();
ddb.middlewareStack.use(createLogConsumedCapacityPlugin(ddb.config));
return DynamoDBDocumentClient.from(ddb);
} |
I may have misunderstood your workflow. In the code provided in the issue description, I saw that |
I have pasted the code above in my comment. Is it not clear? I'm adding the middleware to DynamoDBClient but I use that client for DynamoDBDocumentClient because that's how we need to use the DynamoDBDocumentClient, right? I'm guessing that DynamoDBDocumentClient is doing something to the middleware stack of DynamoDBClient? My middleware has nothing specific to DynamoDBDocumentClient but somehow it's not getting respected when using it that way which is the problem I guess |
While waiting for your feedback, I have tried to add the middleware to the DynamoDBDocumentClient directly but it doesn't work either: // DocumentClient factory which is the one we're really using in our application
export function dynamoDbDocumentClient() {
const ddb = new DynamoDBClient();
const ddbDocumentClient = DynamoDBDocumentClient.from(ddb);
ddbDocumentClient.middlewareStack.use(createLogConsumedCapacityPlugin(ddbDocumentClient.config));
return ddbDocumentClient;
} ConsumedCapacity is also not returned that way. The middleware code is the same from my first post. |
Checkboxes for prior research
Describe the bug
I did a custom DynamoDB client middleware to log used capacity units when a specific environment variable is set by mutating the input to the operations to include the
ReturnConsumedCapacity
when said env variable is configured, but the input that is mutated is ignored completely and only the original command input is serialized in the requestRegression Issue
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.11.0
Reproduction Steps
Observed Behavior
ReturnConsumedCapacity is ignored in the new input
Expected Behavior
ReturnConsumedCapacity should not be ignored and the DynamoDB operations should return the CapacityUnits used
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: