sst 2.16.2 → 2.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/ui/deploy.js +7 -1
- package/constructs/Construct.js +1 -1
- package/constructs/NextjsSite.d.ts +0 -4
- package/constructs/NextjsSite.js +9 -101
- package/constructs/SsrSite.d.ts +4 -3
- package/constructs/SsrSite.js +8 -6
- package/package.json +1 -1
- package/sst.mjs +8 -1
package/cli/ui/deploy.js
CHANGED
|
@@ -111,10 +111,16 @@ function logicalIdToCdkPath(assembly, stack, logicalId) {
|
|
|
111
111
|
return found.split("/").filter(Boolean).slice(1, -1).join("/");
|
|
112
112
|
}
|
|
113
113
|
function getHelper(error) {
|
|
114
|
-
return (
|
|
114
|
+
return (getCloudFrontBehaviorLimitHelper(error) ||
|
|
115
|
+
getApiAccessLogPermissionsHelper(error) ||
|
|
115
116
|
getAppSyncMultiResolverHelper(error) ||
|
|
116
117
|
getApiLogRoleHelper(error));
|
|
117
118
|
}
|
|
119
|
+
function getCloudFrontBehaviorLimitHelper(error) {
|
|
120
|
+
if (error.indexOf("Your request contains more CacheBehaviors than are allowed per distribution.") > -1) {
|
|
121
|
+
return `This error often occurs when deploying a frontend with a large number of top-level files and folders in the assets directory. Check out this doc on how to resolve the issue - https://docs.sst.dev/known-issues#cloudfront-cachebehaviors-limit-exceeded`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
118
124
|
function getApiAccessLogPermissionsHelper(error) {
|
|
119
125
|
// Can run into this issue when enabling access logs for API Gateway
|
|
120
126
|
// note: this should be handled in SST as access log group names are now
|
package/constructs/Construct.js
CHANGED
|
@@ -58,12 +58,8 @@ export declare class NextjsSite extends SsrSite {
|
|
|
58
58
|
private createWarmer;
|
|
59
59
|
protected createCloudFrontDistributionForRegional(): Distribution;
|
|
60
60
|
protected createCloudFrontDistributionForEdge(): Distribution;
|
|
61
|
-
private buildServerBehaviorForRegional;
|
|
62
|
-
private buildServerBehaviorForEdge;
|
|
63
61
|
private buildImageBehavior;
|
|
64
62
|
private buildStaticFileBehavior;
|
|
65
|
-
private buildDefaultNextjsBehaviorForRegional;
|
|
66
|
-
private buildDefaultNextjsBehaviorForEdge;
|
|
67
63
|
protected generateBuildId(): string;
|
|
68
64
|
getConstructMetadata(): {
|
|
69
65
|
data: {
|
package/constructs/NextjsSite.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Fn, Duration as CdkDuration, RemovalPolicy, CustomResource, } from "aws
|
|
|
4
4
|
import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
5
5
|
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
6
6
|
import { Function as CdkFunction, Code, Runtime, Architecture, FunctionUrlAuthType, } from "aws-cdk-lib/aws-lambda";
|
|
7
|
-
import { Distribution, ViewerProtocolPolicy, AllowedMethods,
|
|
8
|
-
import { S3Origin, HttpOrigin
|
|
7
|
+
import { Distribution, ViewerProtocolPolicy, AllowedMethods, CachedMethods, CachePolicy, } from "aws-cdk-lib/aws-cloudfront";
|
|
8
|
+
import { S3Origin, HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
9
9
|
import { Rule, Schedule } from "aws-cdk-lib/aws-events";
|
|
10
10
|
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
|
|
11
11
|
import { Queue } from "aws-cdk-lib/aws-sqs";
|
|
@@ -15,7 +15,6 @@ import { SsrFunction } from "./SsrFunction.js";
|
|
|
15
15
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
16
16
|
import { SsrSite } from "./SsrSite.js";
|
|
17
17
|
import { toCdkSize } from "./util/size.js";
|
|
18
|
-
import { toCdkDuration } from "./util/duration.js";
|
|
19
18
|
/**
|
|
20
19
|
* The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
|
|
21
20
|
* @example
|
|
@@ -239,19 +238,11 @@ export class NextjsSite extends SsrSite {
|
|
|
239
238
|
* - Cache-Control: public, max-age=0, must-revalidate
|
|
240
239
|
* - x-vercel-cache: MISS
|
|
241
240
|
*/
|
|
242
|
-
const {
|
|
241
|
+
const { cdk } = this.props;
|
|
243
242
|
const cfDistributionProps = cdk?.distribution || {};
|
|
244
243
|
const s3Origin = new S3Origin(this.cdk.bucket, {
|
|
245
244
|
originPath: "/" + this.buildConfig.clientBuildS3KeyPrefix,
|
|
246
245
|
});
|
|
247
|
-
const serverFnUrl = this.serverLambdaForRegional.addFunctionUrl({
|
|
248
|
-
authType: FunctionUrlAuthType.NONE,
|
|
249
|
-
});
|
|
250
|
-
const serverOrigin = new HttpOrigin(Fn.parseDomainName(serverFnUrl.url), {
|
|
251
|
-
readTimeout: typeof timeout === "string"
|
|
252
|
-
? toCdkDuration(timeout)
|
|
253
|
-
: CdkDuration.seconds(timeout),
|
|
254
|
-
});
|
|
255
246
|
const cachePolicy = cdk?.serverCachePolicy ??
|
|
256
247
|
this.buildServerCachePolicy([
|
|
257
248
|
"accept",
|
|
@@ -259,8 +250,7 @@ export class NextjsSite extends SsrSite {
|
|
|
259
250
|
"next-router-prefetch",
|
|
260
251
|
"next-router-state-tree",
|
|
261
252
|
]);
|
|
262
|
-
const
|
|
263
|
-
const serverBehavior = this.buildServerBehaviorForRegional(serverOrigin, cachePolicy, originRequestPolicy);
|
|
253
|
+
const serverBehavior = this.buildDefaultBehaviorForRegional(cachePolicy);
|
|
264
254
|
return new Distribution(this, "Distribution", {
|
|
265
255
|
// these values can be overwritten by cfDistributionProps
|
|
266
256
|
defaultRootObject: "",
|
|
@@ -269,12 +259,13 @@ export class NextjsSite extends SsrSite {
|
|
|
269
259
|
// these values can NOT be overwritten by cfDistributionProps
|
|
270
260
|
domainNames: this.buildDistributionDomainNames(),
|
|
271
261
|
certificate: this.cdk.certificate,
|
|
272
|
-
defaultBehavior:
|
|
262
|
+
defaultBehavior: serverBehavior,
|
|
273
263
|
additionalBehaviors: {
|
|
274
264
|
"api/*": serverBehavior,
|
|
275
265
|
"_next/data/*": serverBehavior,
|
|
276
266
|
"_next/image*": this.buildImageBehavior(cachePolicy),
|
|
277
267
|
"_next/*": this.buildStaticFileBehavior(s3Origin),
|
|
268
|
+
...this.buildStaticFileBehaviors(s3Origin),
|
|
278
269
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
279
270
|
},
|
|
280
271
|
});
|
|
@@ -292,9 +283,7 @@ export class NextjsSite extends SsrSite {
|
|
|
292
283
|
"next-router-prefetch",
|
|
293
284
|
"next-router-state-tree",
|
|
294
285
|
]);
|
|
295
|
-
const
|
|
296
|
-
const functionVersion = this.serverLambdaForEdge.currentVersion;
|
|
297
|
-
const serverBehavior = this.buildServerBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy);
|
|
286
|
+
const serverBehavior = this.buildDefaultBehaviorForEdge(s3Origin, cachePolicy);
|
|
298
287
|
return new Distribution(this, "Distribution", {
|
|
299
288
|
// these values can be overwritten by cfDistributionProps
|
|
300
289
|
defaultRootObject: "",
|
|
@@ -303,51 +292,17 @@ export class NextjsSite extends SsrSite {
|
|
|
303
292
|
// these values can NOT be overwritten by cfDistributionProps
|
|
304
293
|
domainNames: this.buildDistributionDomainNames(),
|
|
305
294
|
certificate: this.cdk.certificate,
|
|
306
|
-
defaultBehavior:
|
|
295
|
+
defaultBehavior: serverBehavior,
|
|
307
296
|
additionalBehaviors: {
|
|
308
297
|
"api/*": serverBehavior,
|
|
309
298
|
"_next/data/*": serverBehavior,
|
|
310
299
|
"_next/image*": this.buildImageBehavior(cachePolicy),
|
|
311
300
|
"_next/*": this.buildStaticFileBehavior(s3Origin),
|
|
301
|
+
...this.buildStaticFileBehaviors(s3Origin),
|
|
312
302
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
313
303
|
},
|
|
314
304
|
});
|
|
315
305
|
}
|
|
316
|
-
buildServerBehaviorForRegional(serverOrigin, cachePolicy, originRequestPolicy) {
|
|
317
|
-
const { cdk } = this.props;
|
|
318
|
-
return {
|
|
319
|
-
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
320
|
-
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
321
|
-
origin: serverOrigin,
|
|
322
|
-
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
323
|
-
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
324
|
-
compress: true,
|
|
325
|
-
cachePolicy,
|
|
326
|
-
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
327
|
-
originRequestPolicy,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
buildServerBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy) {
|
|
331
|
-
const { cdk } = this.props;
|
|
332
|
-
return {
|
|
333
|
-
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
334
|
-
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
335
|
-
origin: s3Origin,
|
|
336
|
-
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
337
|
-
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
338
|
-
compress: true,
|
|
339
|
-
cachePolicy,
|
|
340
|
-
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
341
|
-
originRequestPolicy,
|
|
342
|
-
edgeLambdas: [
|
|
343
|
-
{
|
|
344
|
-
includeBody: true,
|
|
345
|
-
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
|
|
346
|
-
functionVersion,
|
|
347
|
-
},
|
|
348
|
-
],
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
306
|
buildImageBehavior(cachePolicy) {
|
|
352
307
|
const { cdk } = this.props;
|
|
353
308
|
const imageFn = this.createImageOptimizationFunction();
|
|
@@ -376,53 +331,6 @@ export class NextjsSite extends SsrSite {
|
|
|
376
331
|
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
377
332
|
};
|
|
378
333
|
}
|
|
379
|
-
buildDefaultNextjsBehaviorForRegional(serverOrigin, s3Origin, cachePolicy, originRequestPolicy) {
|
|
380
|
-
// Create default behavior
|
|
381
|
-
// default handler for requests that don't match any other path:
|
|
382
|
-
// - try lambda handler first
|
|
383
|
-
// - if failed, fall back to S3
|
|
384
|
-
const { cdk } = this.props;
|
|
385
|
-
const cfDistributionProps = cdk?.distribution || {};
|
|
386
|
-
const fallbackOriginGroup = new OriginGroup({
|
|
387
|
-
primaryOrigin: serverOrigin,
|
|
388
|
-
fallbackOrigin: s3Origin,
|
|
389
|
-
fallbackStatusCodes: [503],
|
|
390
|
-
});
|
|
391
|
-
return {
|
|
392
|
-
origin: fallbackOriginGroup,
|
|
393
|
-
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
394
|
-
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
395
|
-
compress: true,
|
|
396
|
-
cachePolicy,
|
|
397
|
-
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
398
|
-
originRequestPolicy,
|
|
399
|
-
...(cfDistributionProps.defaultBehavior || {}),
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
buildDefaultNextjsBehaviorForEdge(functionVersion, s3Origin, cachePolicy, originRequestPolicy) {
|
|
403
|
-
const { cdk } = this.props;
|
|
404
|
-
const cfDistributionProps = cdk?.distribution || {};
|
|
405
|
-
return {
|
|
406
|
-
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
407
|
-
functionAssociations: this.buildBehaviorFunctionAssociations(),
|
|
408
|
-
origin: s3Origin,
|
|
409
|
-
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
410
|
-
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
411
|
-
compress: true,
|
|
412
|
-
cachePolicy,
|
|
413
|
-
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
414
|
-
originRequestPolicy,
|
|
415
|
-
...(cfDistributionProps.defaultBehavior || {}),
|
|
416
|
-
edgeLambdas: [
|
|
417
|
-
{
|
|
418
|
-
includeBody: true,
|
|
419
|
-
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
|
|
420
|
-
functionVersion,
|
|
421
|
-
},
|
|
422
|
-
...(cfDistributionProps.defaultBehavior?.edgeLambdas || []),
|
|
423
|
-
],
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
334
|
generateBuildId() {
|
|
427
335
|
const filePath = path.join(this.props.path, ".next/BUILD_ID");
|
|
428
336
|
return fs.readFileSync(filePath).toString();
|
package/constructs/SsrSite.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Function as CdkFunction, IFunction as ICdkFunction, FunctionProps } fro
|
|
|
4
4
|
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
5
5
|
import { Distribution, ICachePolicy, IResponseHeadersPolicy, BehaviorOptions, CachePolicy, Function as CfFunction, FunctionEventType as CfFunctionEventType } from "aws-cdk-lib/aws-cloudfront";
|
|
6
6
|
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
7
|
+
import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
7
8
|
import { SSTConstruct } from "./Construct.js";
|
|
8
9
|
import { NodeJSProps } from "./Function.js";
|
|
9
10
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
@@ -287,13 +288,13 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
|
|
|
287
288
|
protected createCloudFrontDistributionForRegional(): Distribution;
|
|
288
289
|
protected createCloudFrontDistributionForEdge(): Distribution;
|
|
289
290
|
protected buildDistributionDomainNames(): string[];
|
|
290
|
-
protected buildDefaultBehaviorForRegional(): BehaviorOptions;
|
|
291
|
-
|
|
291
|
+
protected buildDefaultBehaviorForRegional(cachePolicy: ICachePolicy): BehaviorOptions;
|
|
292
|
+
protected buildDefaultBehaviorForEdge(origin: S3Origin, cachePolicy: ICachePolicy): BehaviorOptions;
|
|
292
293
|
protected buildBehaviorFunctionAssociations(): {
|
|
293
294
|
eventType: CfFunctionEventType;
|
|
294
295
|
function: CfFunction;
|
|
295
296
|
}[];
|
|
296
|
-
|
|
297
|
+
protected buildStaticFileBehaviors(origin: S3Origin): Record<string, BehaviorOptions>;
|
|
297
298
|
protected buildServerCachePolicy(allowedHeaders?: string[]): CachePolicy;
|
|
298
299
|
protected buildServerOriginRequestPolicy(): import("aws-cdk-lib/aws-cloudfront").IOriginRequestPolicy;
|
|
299
300
|
private createCloudFrontInvalidation;
|
package/constructs/SsrSite.js
CHANGED
|
@@ -504,6 +504,7 @@ function handler(event) {
|
|
|
504
504
|
const { cdk } = this.props;
|
|
505
505
|
const cfDistributionProps = cdk?.distribution || {};
|
|
506
506
|
const s3Origin = new S3Origin(this.bucket);
|
|
507
|
+
const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
|
|
507
508
|
return new Distribution(this, "Distribution", {
|
|
508
509
|
// these values can be overwritten by cfDistributionProps
|
|
509
510
|
defaultRootObject: "",
|
|
@@ -512,7 +513,7 @@ function handler(event) {
|
|
|
512
513
|
// these values can NOT be overwritten by cfDistributionProps
|
|
513
514
|
domainNames: this.buildDistributionDomainNames(),
|
|
514
515
|
certificate: this.certificate,
|
|
515
|
-
defaultBehavior: this.buildDefaultBehaviorForRegional(),
|
|
516
|
+
defaultBehavior: this.buildDefaultBehaviorForRegional(cachePolicy),
|
|
516
517
|
additionalBehaviors: {
|
|
517
518
|
...this.buildStaticFileBehaviors(s3Origin),
|
|
518
519
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
@@ -523,6 +524,7 @@ function handler(event) {
|
|
|
523
524
|
const { cdk } = this.props;
|
|
524
525
|
const cfDistributionProps = cdk?.distribution || {};
|
|
525
526
|
const s3Origin = new S3Origin(this.bucket);
|
|
527
|
+
const cachePolicy = cdk?.serverCachePolicy ?? this.buildServerCachePolicy();
|
|
526
528
|
return new Distribution(this, "Distribution", {
|
|
527
529
|
// these values can be overwritten by cfDistributionProps
|
|
528
530
|
defaultRootObject: "",
|
|
@@ -531,7 +533,7 @@ function handler(event) {
|
|
|
531
533
|
// these values can NOT be overwritten by cfDistributionProps
|
|
532
534
|
domainNames: this.buildDistributionDomainNames(),
|
|
533
535
|
certificate: this.certificate,
|
|
534
|
-
defaultBehavior: this.buildDefaultBehaviorForEdge(s3Origin),
|
|
536
|
+
defaultBehavior: this.buildDefaultBehaviorForEdge(s3Origin, cachePolicy),
|
|
535
537
|
additionalBehaviors: {
|
|
536
538
|
...this.buildStaticFileBehaviors(s3Origin),
|
|
537
539
|
...(cfDistributionProps.additionalBehaviors || {}),
|
|
@@ -557,7 +559,7 @@ function handler(event) {
|
|
|
557
559
|
}
|
|
558
560
|
return domainNames;
|
|
559
561
|
}
|
|
560
|
-
buildDefaultBehaviorForRegional() {
|
|
562
|
+
buildDefaultBehaviorForRegional(cachePolicy) {
|
|
561
563
|
const { timeout, cdk } = this.props;
|
|
562
564
|
const cfDistributionProps = cdk?.distribution || {};
|
|
563
565
|
const fnUrl = this.serverLambdaForRegional.addFunctionUrl({
|
|
@@ -573,7 +575,7 @@ function handler(event) {
|
|
|
573
575
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
574
576
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
575
577
|
compress: true,
|
|
576
|
-
cachePolicy
|
|
578
|
+
cachePolicy,
|
|
577
579
|
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
578
580
|
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
579
581
|
...(cfDistributionProps.defaultBehavior || {}),
|
|
@@ -583,7 +585,7 @@ function handler(event) {
|
|
|
583
585
|
],
|
|
584
586
|
};
|
|
585
587
|
}
|
|
586
|
-
buildDefaultBehaviorForEdge(origin) {
|
|
588
|
+
buildDefaultBehaviorForEdge(origin, cachePolicy) {
|
|
587
589
|
const { cdk } = this.props;
|
|
588
590
|
const cfDistributionProps = cdk?.distribution || {};
|
|
589
591
|
return {
|
|
@@ -592,7 +594,7 @@ function handler(event) {
|
|
|
592
594
|
allowedMethods: AllowedMethods.ALLOW_ALL,
|
|
593
595
|
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
|
|
594
596
|
compress: true,
|
|
595
|
-
cachePolicy
|
|
597
|
+
cachePolicy,
|
|
596
598
|
responseHeadersPolicy: cdk?.responseHeadersPolicy,
|
|
597
599
|
originRequestPolicy: this.buildServerOriginRequestPolicy(),
|
|
598
600
|
...(cfDistributionProps.defaultBehavior || {}),
|
package/package.json
CHANGED
package/sst.mjs
CHANGED
|
@@ -6222,7 +6222,14 @@ function logicalIdToCdkPath(assembly, stack, logicalId) {
|
|
|
6222
6222
|
return found.split("/").filter(Boolean).slice(1, -1).join("/");
|
|
6223
6223
|
}
|
|
6224
6224
|
function getHelper(error2) {
|
|
6225
|
-
return getApiAccessLogPermissionsHelper(error2) || getAppSyncMultiResolverHelper(error2) || getApiLogRoleHelper(error2);
|
|
6225
|
+
return getCloudFrontBehaviorLimitHelper(error2) || getApiAccessLogPermissionsHelper(error2) || getAppSyncMultiResolverHelper(error2) || getApiLogRoleHelper(error2);
|
|
6226
|
+
}
|
|
6227
|
+
function getCloudFrontBehaviorLimitHelper(error2) {
|
|
6228
|
+
if (error2.indexOf(
|
|
6229
|
+
"Your request contains more CacheBehaviors than are allowed per distribution."
|
|
6230
|
+
) > -1) {
|
|
6231
|
+
return `This error often occurs when deploying a frontend with a large number of top-level files and folders in the assets directory. Check out this doc on how to resolve the issue - https://docs.sst.dev/known-issues#cloudfront-cachebehaviors-limit-exceeded`;
|
|
6232
|
+
}
|
|
6226
6233
|
}
|
|
6227
6234
|
function getApiAccessLogPermissionsHelper(error2) {
|
|
6228
6235
|
if (error2.indexOf("Insufficient permissions to enable logging") > -1) {
|