Skip to content

Commit

Permalink
fix(nextjs-component, nextjs-cdk-construct): create AWS resources for…
Browse files Browse the repository at this point in the history
… dynamic SSG (#1476) (#1477)
  • Loading branch information
laiso committed Aug 3, 2021
1 parent b50c257 commit 7e9c923
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/serverless-components/nextjs-cdk-construct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions packages/serverless-components/nextjs-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,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,
Expand All @@ -472,7 +478,7 @@ class NextjsComponent extends Component {
};

let queue;
if (hasISRPages) {
if (hasISRPages || hasDynamicISRPages) {
queue = await sqs({
name: `${bucketOutputs.name}.fifo`,
deduplicationScope: "messageGroup",
Expand Down Expand Up @@ -522,7 +528,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
Expand Down

0 comments on commit 7e9c923

Please sign in to comment.