diff --git a/packages/serverless-components/nextjs-cdk-construct/src/index.ts b/packages/serverless-components/nextjs-cdk-construct/src/index.ts index 5ac70aecf1..9623c17a0e 100644 --- a/packages/serverless-components/nextjs-cdk-construct/src/index.ts +++ b/packages/serverless-components/nextjs-cdk-construct/src/index.ts @@ -95,7 +95,13 @@ export class NextJSLambdaEdge extends cdk.Construct { "number" ); - if (hasISRPages) { + const hasDynamicISRPages = Object.keys( + this.prerenderManifest.dynamicRoutes + ).some( + (key) => this.prerenderManifest.dynamicRoutes[key].fallback !== false + ); + + if (hasISRPages || hasDynamicISRPages) { this.regenerationQueue = new sqs.Queue(this, "RegenerationQueue", { // We call the queue the same name as the bucket so that we can easily // reference it from within the lambda@edge, given we can't use env vars @@ -160,7 +166,7 @@ export class NextJSLambdaEdge extends cdk.Construct { this.bucket.grantReadWrite(this.defaultNextLambda); this.defaultNextLambda.currentVersion.addAlias("live"); - if (hasISRPages && this.regenerationFunction) { + if ((hasISRPages || hasDynamicISRPages) && this.regenerationFunction) { this.bucket.grantReadWrite(this.regenerationFunction); this.regenerationQueue?.grantSendMessages(this.defaultNextLambda); this.regenerationFunction?.grantInvoke(this.defaultNextLambda); diff --git a/packages/serverless-components/nextjs-component/src/component.ts b/packages/serverless-components/nextjs-component/src/component.ts index d614d28af9..9666007c41 100644 --- a/packages/serverless-components/nextjs-component/src/component.ts +++ b/packages/serverless-components/nextjs-component/src/component.ts @@ -452,6 +452,12 @@ class NextjsComponent extends Component { .initialRevalidateSeconds === "number" ); + const hasDynamicISRPages = Object.keys( + defaultBuildManifest.pages.ssg.dynamic + ).some( + (key) => defaultBuildManifest.pages.ssg.dynamic[key].fallback !== false + ); + const readLambdaInputValue = ( inputKey: "memory" | "timeout" | "name" | "runtime" | "roleArn" | "tags", lambdaType: LambdaType, @@ -471,7 +477,7 @@ class NextjsComponent extends Component { }; let queue; - if (hasISRPages) { + if (hasISRPages || hasDynamicISRPages) { queue = await sqs({ name: `${bucketOutputs.name}.fifo`, deduplicationScope: "messageGroup", @@ -521,7 +527,7 @@ class NextjsComponent extends Component { } } - if (hasISRPages) { + if (hasISRPages || hasDynamicISRPages) { const regenerationLambdaInput: LambdaInput = { region: bucketRegion, // make sure SQS region and regeneration lambda region are the same description: inputs.description