Skip to content

Commit 43f401b

Browse files
authored
feat(client-sqs): add option to prevent md5 computation (#5953)
* feat(client-sqs): add option to prevent md5 computation * feat(client-sqs): handle md5=false in sqs middleware
1 parent 885b47e commit 43f401b

File tree

9 files changed

+55
-15
lines changed

9 files changed

+55
-15
lines changed

UPGRADING.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ In v3, the similar utility function is available in [`@aws-sdk/polly-request-pre
573573

574574
### Amazon S3
575575

576-
Streaming vs. buffered responses: the JSv3 SDK prefers not to buffer potentially large responses. This is commonly encountered in S3's GetObject operation, which returned a `Buffer` in JSv2, but
576+
Streaming vs. buffered responses: the JSv3 SDK prefers not to buffer potentially large responses. This is commonly encountered in S3's GetObject operation, which returned a `Buffer` in JSv2, but
577577
returns a `Stream` in JSv3.
578578

579-
For Node.js, you must consume the stream or garbage collect the client or its request handler to keep the connections open to new traffic by freeing sockets.
579+
For Node.js, you must consume the stream or garbage collect the client or its request handler to keep the connections open to new traffic by freeing sockets.
580580

581581
```ts
582582
// v2
@@ -642,7 +642,22 @@ const region = "...";
642642

643643
### Amazon SQS
644644

645-
When using a custom `QueueUrl` in SQS operations that have this as an input parameter, in JSv2
645+
#### MD5 Checksum
646+
647+
To skip computation of MD5 checksums of message bodies, set `md5=false` on the configuration object.
648+
Otherwise, by default the SDK will calculate the checksum for sending messages, as well as validating the checksum
649+
for retrieved messages.
650+
651+
```ts
652+
// Example: skip md5 checksum in SQS.
653+
import { SQS } from "@aws-sdk/client-sqs";
654+
655+
new SQS({
656+
md5: false, // Note: only available in v3.547.0 and higher.
657+
});
658+
```
659+
660+
When using a custom `QueueUrl` in SQS operations that have this as an input parameter, in JSv2
646661
it was possible to supply a custom `QueueUrl` which would override the SQS Client's default endpoint.
647662

648663
#### Mutli-region messages
@@ -669,11 +684,11 @@ for (const { region, url } of queues) {
669684
};
670685
await sqsClients[region].sendMessage(params);
671686
}
672-
```
687+
```
673688

674689
#### Custom endpoint
675690

676-
In JSv3, when using a custom endpoint, i.e. one that differs from the default public SQS endpoints, you
691+
In JSv3, when using a custom endpoint, i.e. one that differs from the default public SQS endpoints, you
677692
should always set the endpoint on the SQS Client as well as the `QueueUrl` field.
678693

679694
```ts
@@ -703,6 +718,6 @@ const sqs = new SQS({
703718

704719
await sqs.sendMessage({
705720
QueueUrl: "https://sqs.us-west-2.amazonaws.com/1234567/MyQueue",
706-
Message: "hello"
721+
Message: "hello",
707722
});
708723
```

clients/client-sqs/src/SQSClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
257257

258258
/**
259259
* A constructor for a class implementing the {@link __Checksum} interface
260-
* that computes MD5 hashes.
261-
* @internal
260+
* that computes MD5 hashes, or false to prevent MD5 computation.
262261
*/
263-
md5?: __ChecksumConstructor | __HashConstructor;
262+
md5?: __ChecksumConstructor | __HashConstructor | false;
264263

265264
/**
266265
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddSqsDependency.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ public void addConfigInterfaceFields(
8787
writer.addImport("Checksum", "__Checksum", TypeScriptDependency.SMITHY_TYPES);
8888
writer.addImport("ChecksumConstructor", "__ChecksumConstructor", TypeScriptDependency.SMITHY_TYPES);
8989
writer.writeDocs("A constructor for a class implementing the {@link __Checksum} interface \n"
90-
+ "that computes MD5 hashes.\n"
91-
+ "@internal");
92-
writer.write("md5?: __ChecksumConstructor | __HashConstructor;\n");
90+
+ "that computes MD5 hashes, or false to prevent MD5 computation.");
91+
writer.write("md5?: __ChecksumConstructor | __HashConstructor | false;\n");
9392
}
9493

9594
@Override
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChecksumConstructor, HashConstructor } from "@smithy/types";
22

33
export interface PreviouslyResolved {
4-
md5: ChecksumConstructor | HashConstructor;
4+
md5: ChecksumConstructor | HashConstructor | false;
55
}

packages/middleware-sdk-sqs/src/middleware-sdk-sqs.integ.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ const handlerResponse = (body: string) => {
103103
};
104104

105105
describe("middleware-sdk-sqs", () => {
106-
// TODO: check in CI
107-
xdescribe(SQS.name + ` w/ useAwsQuery: ${useAwsQuery}`, () => {
106+
describe(SQS.name + ` w/ useAwsQuery: ${useAwsQuery}`, () => {
108107
describe("correct md5 hashes", () => {
109108
beforeEach(() => {
110109
hashError = "";

packages/middleware-sdk-sqs/src/receive-message.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export function receiveMessageMiddleware(options: PreviouslyResolved): Initializ
2626
return <Output extends MetadataBearer>(next: InitializeHandler<any, Output>): InitializeHandler<any, Output> =>
2727
async (args: InitializeHandlerArguments<any>): Promise<InitializeHandlerOutput<Output>> => {
2828
const resp = await next({ ...args });
29+
if (options.md5 === false) {
30+
return resp;
31+
}
2932
const output = resp.output as unknown as ReceiveMessageResult;
3033
const messageIds = [];
3134
if (output.Messages !== undefined) {

packages/middleware-sdk-sqs/src/receive-messages.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,23 @@ describe("receiveMessageMiddleware", () => {
6969
expect(mockHashUpdate.mock.calls.length).toBe(2);
7070
expect(mockHashDigest.mock.calls.length).toBe(2);
7171
});
72+
73+
it("ignores checksum if md5=false in config", async () => {
74+
const next = jest.fn().mockReturnValue({
75+
output: {
76+
Messages: [
77+
{ Body: "foo", MD5OfBody: "XXYYZZ", MessageId: "fooMessage" },
78+
{ Body: "bar", MD5OfBody: "XXYYZZ", MessageId: "barMessage" },
79+
],
80+
},
81+
});
82+
const handler = receiveMessageMiddleware({
83+
md5: false,
84+
})(next, {} as any);
85+
86+
await handler({ input: {} });
87+
88+
expect(mockHashUpdate.mock.calls.length).toBe(0);
89+
expect(mockHashDigest.mock.calls.length).toBe(0);
90+
});
7291
});

packages/middleware-sdk-sqs/src/send-message-batch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export const sendMessageBatchMiddleware =
2727
<Output extends MetadataBearer>(next: InitializeHandler<any, Output>): InitializeHandler<any, Output> =>
2828
async (args: InitializeHandlerArguments<any>): Promise<InitializeHandlerOutput<Output>> => {
2929
const resp = await next({ ...args });
30+
if (options.md5 === false) {
31+
return resp;
32+
}
3033
const output = resp.output as unknown as SendMessageBatchResult;
3134
const messageIds = [];
3235
const entries: Record<string, SendMessageBatchResultEntry> = {};

packages/middleware-sdk-sqs/src/send-message.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const sendMessageMiddleware =
2121
<Output extends MetadataBearer>(next: InitializeHandler<any, Output>): InitializeHandler<any, Output> =>
2222
async (args: InitializeHandlerArguments<any>): Promise<InitializeHandlerOutput<Output>> => {
2323
const resp = await next({ ...args });
24+
if (options.md5 === false) {
25+
return resp;
26+
}
2427
const output = resp.output as SendMessageResult;
2528
const hash = new options.md5();
2629
hash.update(toUint8Array(args.input.MessageBody || ""));

0 commit comments

Comments
 (0)