Skip to content

Commit a28ec93

Browse files
committed
fix(nextjs-component, nextjs-cdk-construct): create AWS resources for dynamic SSG (serverless-nextjs#1476)
1 parent a5d74d2 commit a28ec93

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
@@ -452,6 +452,12 @@ class NextjsComponent extends Component {
452452
.initialRevalidateSeconds === "number"
453453
);
454454

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

473479
let queue;
474-
if (hasISRPages) {
480+
if (hasISRPages || hasDynamicISRPages) {
475481
queue = await sqs({
476482
name: `${bucketOutputs.name}.fifo`,
477483
deduplicationScope: "messageGroup",
@@ -521,7 +527,7 @@ class NextjsComponent extends Component {
521527
}
522528
}
523529

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

0 commit comments

Comments
 (0)