Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 1b758c8

Browse files
authored
fix(lambda-at-edge): sqs messageGroupId should be a hash to allow for long URIs (#1621)
1 parent 3eb8f15 commit 1b758c8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/libs/lambda-at-edge/src/lib/triggerStaticRegeneration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { s3BucketNameFromEventRequest } from "../s3/s3BucketNameFromEventRequest";
22
import { RegenerationEvent } from "../types";
3+
import * as crypto from "crypto";
34

45
interface TriggerStaticRegenerationOptions {
56
request: AWSLambda.CloudFrontRequest;
@@ -39,6 +40,13 @@ export const triggerStaticRegeneration = async (
3940
};
4041

4142
try {
43+
// Hash URI for messageGroupId to allow for long URIs, as SQS has limit of 128 characters
44+
// MD5 is used since this is only used for grouping purposes
45+
const hashedUri = crypto
46+
.createHash("md5")
47+
.update(options.request.uri)
48+
.digest("hex");
49+
4250
await sqs.send(
4351
new SendMessageCommand({
4452
QueueUrl: `https://sqs.${region}.amazonaws.com/${queueName}`,
@@ -53,7 +61,7 @@ export const triggerStaticRegeneration = async (
5361
.toString(),
5462
// Only deduplicate based on the object, i.e. we can generate
5563
// different pages in parallel, just not the same one
56-
MessageGroupId: options.request.uri
64+
MessageGroupId: hashedUri
5765
})
5866
);
5967
return { throttle: false };

packages/libs/lambda-at-edge/tests/utils/triggerStaticRegeneration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe("triggerStaticRegeneration()", () => {
118118
pagePath: "/"
119119
}),
120120
MessageDeduplicationId: expected,
121-
MessageGroupId: "index.html"
121+
MessageGroupId: "eacf331f0ffc35d4b482f1d15a887d3b" // md5 hash of "index.html"
122122
});
123123
}
124124
);

0 commit comments

Comments
 (0)