Skip to content

Support Command class instance reuse in all clients and @aws-sdk/lib-dynamodb #7217

@kuhe

Description

@kuhe

Checkboxes for prior research

Describe the bug

In AWS SDK for JavaScript conventions, a Client may be used to send one or more Commands.

e.g.

import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";

const client = new S3Client();

const params = { ... };

const command = new GetObjectCommand(params);

await client.send(command);

Command reuse is the act of sending a command more than once in the same client, e.g.

const command = new GetObjectCommand({ ... });

await client.send(command);
await client.send(command);
await client.send(command);

Because commands only save a reference to their input params, it is possible to change params between repeated calls to client.send.

⚠️ This style is not recommended by our documentation.

const command = new GetObjectCommand({ ... });

const response1 = await client.send(command);
params.Key = "2";
const response2 = await client.send(command);
params.Key = "3";
const response3 = await client.send(command);

⚠️ However, because we did not explicitly discourage this with documentation or runtime errors, we are planning to support this use-case as-is, and formalize its validity by covering the use case with integration tests.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

any supported version

Reproduction Steps

In v3.778.0 of @aws-sdk/lib-dynamodb, the DynamoDBDocumentClient attributeValue wrapper class broke the usage pattern of Command reuse.

We are applying a patch in #7216 to formalize and protect the ability to reuse Commands.

Observed Behavior

Reused Commands from the DynamoDBDocumentClient would undergo the marshalling transform more than once, leading to incorrect serialized data.

The transform is specific to this high-level Client and does not affect other clients or other services.

Expected Behavior

Command class instances from @aws-sdk/lib-dynamodb for the DynamoDBDocumentClient wrapper client should be reusable.

Possible Solution

Fix applied in #7216

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.closing-soonThis issue will automatically close in 4 days unless further comments are made.feature-requestNew feature or enhancement. May require GitHub community feedback.potential-regressionMarking this issue as a potential regression to be checked by team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions