Skip to content

MiddlewareStacks added to commands in lib-dynamodb never get applied. #3095

Closed
@c0pp3rt0p

Description

@c0pp3rt0p

Describe the bug

Commands in lib-dynamodb do not add their middelwareStack to the underlying command.

Adding any middleware stack to a command in the lib-dynamodb package has no effect.

Your environment

NodeJs/TS on mac

SDK version number

@aws-sdk/package-name@3.43.0

Is the issue in the browser/Node.js/ReactNative?

no

Details of the browser/Node.js/ReactNative version

$ node -v
v14.17.0

Steps to reproduce

Please share code or minimal repo, and steps to reproduce the behavior.

import { QueryCommand } from '@aws-sdk/lib-dynamodb';
import { dynamoDocClient } from './dynamodb-client';

        const cmd = new QueryCommand({
          TableName: "MyTable",
          KeyConditionExpression: "id = :id",
          ExpressionAttributeValues: {
            ':id': id,
          },
        });
        cmd.middlewareStack.add(
          (next) => async (args) => {
            console.log('You will never see this');
            const result = await next(args);
            // result.response contains data returned from next middleware.
            return result;
          },
          {
            step: 'build',
            name: 'addFooMetadataMiddleware',
            tags: ['METADATA', 'FOO'],
          }
        );
      const dynamoDocClient = await client.send(cmd);
      // 

Observed behavior

The expected console output "You will never see this", is never shown.

Expected behavior

when the command is sent "You will never see this" should be output to the console.

Additional context

It appears the commands in lib-dynamodb are missing the step to concat the current middleware with the newly constructed command. Only the client middlewares get resolved. See comments in the code below.

link to relevant code:

const handler = command.resolveMiddleware(clientStack, configuration, options);

resolveMiddleware(clientStack, configuration, options) {
        const { marshallOptions, unmarshallOptions } = configuration.translateConfig || {};
        const command = new client_dynamodb_1.QueryCommand(utils_1.marshallInput(this.input, this.inputKeyNodes, marshallOptions));
       // need to concat the current middlewareStack with the constructed client.
        const stack = clientStack.concat(this.middlewareStack);
       // resolve the newly combined stack
        const handler = command.resolveMiddleware(stack, configuration, options);
        return async () => {
            const data = await handler(command);
            return {
                ...data,
                output: utils_1.unmarshallOutput(data.output, this.outputKeyNodes, unmarshallOptions),
            };
        };
    }

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions