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

Commit 7e9c923

Browse files
authored
fix(nextjs-component, nextjs-cdk-construct): create AWS resources for dynamic SSG (#1476) (#1477)
1 parent b50c257 commit 7e9c923

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/serverless-components/nextjs-cdk-construct/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ export class NextJSLambdaEdge extends cdk.Construct {
9595
"number"
9696
);
9797

98-
if (hasISRPages) {
98+
const hasDynamicISRPages = Object.keys(
99+
this.prerenderManifest.dynamicRoutes
100+
).some(
101+
(key) => this.prerenderManifest.dynamicRoutes[key].fallback !== false
102+
);
103+
104+
if (hasISRPages || hasDynamicISRPages) {
99105
this.regenerationQueue = new sqs.Queue(this, "RegenerationQueue", {
100106
// We call the queue the same name as the bucket so that we can easily
101107
// reference it from within the lambda@edge, given we can't use env vars
@@ -160,7 +166,7 @@ export class NextJSLambdaEdge extends cdk.Construct {
160166
this.bucket.grantReadWrite(this.defaultNextLambda);
161167
this.defaultNextLambda.currentVersion.addAlias("live");
162168

163-
if (hasISRPages && this.regenerationFunction) {
169+
if ((hasISRPages || hasDynamicISRPages) && this.regenerationFunction) {
164170
this.bucket.grantReadWrite(this.regenerationFunction);
165171
this.regenerationQueue?.grantSendMessages(this.defaultNextLambda);
166172
this.regenerationFunction?.grantInvoke(this.defaultNextLambda);

packages/serverless-components/nextjs-component/src/component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ class NextjsComponent extends Component {
453453
.initialRevalidateSeconds === "number"
454454
);
455455

456+
const hasDynamicISRPages = Object.keys(
457+
defaultBuildManifest.pages.ssg.dynamic
458+
).some(
459+
(key) => defaultBuildManifest.pages.ssg.dynamic[key].fallback !== false
460+
);
461+
456462
const readLambdaInputValue = (
457463
inputKey: "memory" | "timeout" | "name" | "runtime" | "roleArn" | "tags",
458464
lambdaType: LambdaType,
@@ -472,7 +478,7 @@ class NextjsComponent extends Component {
472478
};
473479

474480
let queue;
475-
if (hasISRPages) {
481+
if (hasISRPages || hasDynamicISRPages) {
476482
queue = await sqs({
477483
name: `${bucketOutputs.name}.fifo`,
478484
deduplicationScope: "messageGroup",
@@ -522,7 +528,7 @@ class NextjsComponent extends Component {
522528
}
523529
}
524530

525-
if (hasISRPages) {
531+
if (hasISRPages || hasDynamicISRPages) {
526532
const regenerationLambdaInput: LambdaInput = {
527533
region: bucketRegion, // make sure SQS region and regeneration lambda region are the same
528534
description: inputs.description

0 commit comments

Comments
 (0)