sst 2.0.27 → 2.0.29
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/constructs/NextjsSite.js +7 -0
- package/constructs/SsrSite.js +3 -2
- package/constructs/StaticSite.d.ts +10 -10
- package/constructs/StaticSite.js +27 -25
- package/package.json +1 -1
package/constructs/NextjsSite.js
CHANGED
|
@@ -10,6 +10,7 @@ import { SsrFunction } from "./SsrFunction.js";
|
|
|
10
10
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
11
11
|
import { SsrSite } from "./SsrSite.js";
|
|
12
12
|
import { toCdkSize } from "./util/size.js";
|
|
13
|
+
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
13
14
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
14
15
|
/**
|
|
15
16
|
* The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
|
|
@@ -72,6 +73,12 @@ export class NextjsSite extends SsrSite {
|
|
|
72
73
|
environment: {
|
|
73
74
|
BUCKET_NAME: this.cdk.bucket.bucketName,
|
|
74
75
|
},
|
|
76
|
+
initialPolicy: [
|
|
77
|
+
new PolicyStatement({
|
|
78
|
+
actions: ["s3:GetObject"],
|
|
79
|
+
resources: [this.cdk.bucket.arnForObjects("*")],
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
84
|
createMiddlewareEdgeFunctionForRegional() {
|
package/constructs/SsrSite.js
CHANGED
|
@@ -7,7 +7,7 @@ import spawn from "cross-spawn";
|
|
|
7
7
|
import { execSync } from "child_process";
|
|
8
8
|
import { Construct } from "constructs";
|
|
9
9
|
import { Fn, Token, Duration as CdkDuration, CfnOutput, RemovalPolicy, CustomResource, } from "aws-cdk-lib";
|
|
10
|
-
import { Bucket } from "aws-cdk-lib/aws-s3";
|
|
10
|
+
import { BlockPublicAccess, Bucket, } from "aws-cdk-lib/aws-s3";
|
|
11
11
|
import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
12
12
|
import { Function, Code, Runtime, FunctionUrlAuthType, } from "aws-cdk-lib/aws-lambda";
|
|
13
13
|
import { HostedZone, ARecord, AaaaRecord, RecordTarget, } from "aws-cdk-lib/aws-route53";
|
|
@@ -330,7 +330,8 @@ export class SsrSite extends Construct {
|
|
|
330
330
|
else {
|
|
331
331
|
const bucketProps = cdk?.bucket;
|
|
332
332
|
return new Bucket(this, "S3Bucket", {
|
|
333
|
-
publicReadAccess:
|
|
333
|
+
publicReadAccess: false,
|
|
334
|
+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
|
334
335
|
autoDeleteObjects: true,
|
|
335
336
|
removalPolicy: RemovalPolicy.DESTROY,
|
|
336
337
|
...bucketProps,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Construct } from "constructs";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
|
|
3
|
+
import { ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
4
|
+
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
5
|
+
import { Distribution } from "aws-cdk-lib/aws-cloudfront";
|
|
6
6
|
import { BaseSiteDomainProps, BaseSiteReplaceProps, BaseSiteCdkDistributionProps } from "./BaseSite.js";
|
|
7
7
|
import { SSTConstruct } from "./Construct.js";
|
|
8
8
|
import { FunctionBindingProps } from "./util/functionBinding.js";
|
|
@@ -240,7 +240,7 @@ export interface StaticSiteProps {
|
|
|
240
240
|
* });
|
|
241
241
|
* ```
|
|
242
242
|
*/
|
|
243
|
-
bucket?:
|
|
243
|
+
bucket?: BucketProps | IBucket;
|
|
244
244
|
/**
|
|
245
245
|
* Configure the internally created CDK `Distribution` instance.
|
|
246
246
|
*
|
|
@@ -301,10 +301,10 @@ export declare class StaticSite extends Construct implements SSTConstruct {
|
|
|
301
301
|
* The internally created CDK resources.
|
|
302
302
|
*/
|
|
303
303
|
get cdk(): {
|
|
304
|
-
bucket:
|
|
305
|
-
distribution:
|
|
306
|
-
hostedZone:
|
|
307
|
-
certificate:
|
|
304
|
+
bucket: Bucket;
|
|
305
|
+
distribution: Distribution;
|
|
306
|
+
hostedZone: IHostedZone | undefined;
|
|
307
|
+
certificate: ICertificate | undefined;
|
|
308
308
|
};
|
|
309
309
|
getConstructMetadata(): {
|
|
310
310
|
type: "StaticSite";
|
|
@@ -325,7 +325,7 @@ export declare class StaticSite extends Construct implements SSTConstruct {
|
|
|
325
325
|
private createCfDistribution;
|
|
326
326
|
private createCloudFrontInvalidation;
|
|
327
327
|
protected validateCustomDomainSettings(): void;
|
|
328
|
-
protected lookupHostedZone():
|
|
328
|
+
protected lookupHostedZone(): IHostedZone | undefined;
|
|
329
329
|
private createCertificate;
|
|
330
330
|
protected createRoute53Records(): void;
|
|
331
331
|
private getS3ContentReplaceValues;
|
package/constructs/StaticSite.js
CHANGED
|
@@ -5,14 +5,14 @@ import crypto from "crypto";
|
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
6
|
import { Construct } from "constructs";
|
|
7
7
|
import { Token, Duration, CfnOutput, RemovalPolicy, CustomResource, } from "aws-cdk-lib";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import { BlockPublicAccess, Bucket, } from "aws-cdk-lib/aws-s3";
|
|
9
|
+
import { Asset } from "aws-cdk-lib/aws-s3-assets";
|
|
10
10
|
import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
11
|
+
import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
12
|
+
import { HostedZone, ARecord, AaaaRecord, RecordTarget, } from "aws-cdk-lib/aws-route53";
|
|
13
|
+
import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets";
|
|
14
|
+
import { Distribution, ViewerProtocolPolicy } from "aws-cdk-lib/aws-cloudfront";
|
|
15
|
+
import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
|
|
16
16
|
import { AwsCliLayer } from "aws-cdk-lib/lambda-layer-awscli";
|
|
17
17
|
import { Stack } from "./Stack.js";
|
|
18
18
|
import { getBuildCmdEnvironment, buildErrorResponsesFor404ErrorPage, buildErrorResponsesForRedirectToIndex, } from "./BaseSite.js";
|
|
@@ -252,7 +252,7 @@ interface ImportMeta {
|
|
|
252
252
|
if (!fs.existsSync(zipFilePath)) {
|
|
253
253
|
break;
|
|
254
254
|
}
|
|
255
|
-
assets.push(new
|
|
255
|
+
assets.push(new Asset(this, `Asset${partId}`, {
|
|
256
256
|
path: zipFilePath,
|
|
257
257
|
}));
|
|
258
258
|
}
|
|
@@ -268,7 +268,7 @@ interface ImportMeta {
|
|
|
268
268
|
if (!fs.existsSync(filenamesPath)) {
|
|
269
269
|
throw new Error(`There was a problem generating the "${this.node.id}" StaticSite package.`);
|
|
270
270
|
}
|
|
271
|
-
return new
|
|
271
|
+
return new Asset(this, `AssetFilenames`, {
|
|
272
272
|
path: filenamesPath,
|
|
273
273
|
});
|
|
274
274
|
}
|
|
@@ -288,7 +288,9 @@ interface ImportMeta {
|
|
|
288
288
|
if (bucketProps?.websiteErrorDocument) {
|
|
289
289
|
throw new Error(`Do not configure the "s3Bucket.websiteErrorDocument". Use the "errorPage" to configure the StaticSite index page.`);
|
|
290
290
|
}
|
|
291
|
-
return new
|
|
291
|
+
return new Bucket(this, "S3Bucket", {
|
|
292
|
+
publicReadAccess: false,
|
|
293
|
+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
|
292
294
|
autoDeleteObjects: true,
|
|
293
295
|
removalPolicy: RemovalPolicy.DESTROY,
|
|
294
296
|
...bucketProps,
|
|
@@ -309,10 +311,10 @@ interface ImportMeta {
|
|
|
309
311
|
},
|
|
310
312
|
];
|
|
311
313
|
// Create a Lambda function that will be doing the uploading
|
|
312
|
-
const uploader = new
|
|
313
|
-
code:
|
|
314
|
+
const uploader = new Function(this, "S3Uploader", {
|
|
315
|
+
code: Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
|
|
314
316
|
layers: [cliLayer],
|
|
315
|
-
runtime:
|
|
317
|
+
runtime: Runtime.PYTHON_3_7,
|
|
316
318
|
handler: "s3-upload.handler",
|
|
317
319
|
timeout: Duration.minutes(15),
|
|
318
320
|
memorySize: 1024,
|
|
@@ -320,10 +322,10 @@ interface ImportMeta {
|
|
|
320
322
|
this.bucket.grantReadWrite(uploader);
|
|
321
323
|
assets.forEach((asset) => asset.grantRead(uploader));
|
|
322
324
|
// Create the custom resource function
|
|
323
|
-
const handler = new
|
|
324
|
-
code:
|
|
325
|
+
const handler = new Function(this, "S3Handler", {
|
|
326
|
+
code: Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
|
|
325
327
|
layers: [cliLayer],
|
|
326
|
-
runtime:
|
|
328
|
+
runtime: Runtime.PYTHON_3_7,
|
|
327
329
|
handler: "s3-handler.handler",
|
|
328
330
|
timeout: Duration.minutes(15),
|
|
329
331
|
memorySize: 1024,
|
|
@@ -403,7 +405,7 @@ interface ImportMeta {
|
|
|
403
405
|
const { cdk, errorPage } = this.props;
|
|
404
406
|
const indexPage = this.props.indexPage || "index.html";
|
|
405
407
|
// Create CloudFront distribution
|
|
406
|
-
return new
|
|
408
|
+
return new Distribution(this, "Distribution", {
|
|
407
409
|
// these values can be overwritten by cfDistributionProps
|
|
408
410
|
defaultRootObject: indexPage,
|
|
409
411
|
errorResponses: !errorPage || errorPage === "redirect_to_index_page"
|
|
@@ -414,8 +416,8 @@ interface ImportMeta {
|
|
|
414
416
|
domainNames: this.buildDistributionDomainNames(),
|
|
415
417
|
certificate: this.certificate,
|
|
416
418
|
defaultBehavior: {
|
|
417
|
-
origin: new
|
|
418
|
-
viewerProtocolPolicy:
|
|
419
|
+
origin: new S3Origin(this.bucket),
|
|
420
|
+
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
419
421
|
...cdk?.distribution?.defaultBehavior,
|
|
420
422
|
},
|
|
421
423
|
});
|
|
@@ -486,7 +488,7 @@ interface ImportMeta {
|
|
|
486
488
|
}
|
|
487
489
|
let hostedZone;
|
|
488
490
|
if (typeof customDomain === "string") {
|
|
489
|
-
hostedZone =
|
|
491
|
+
hostedZone = HostedZone.fromLookup(this, "HostedZone", {
|
|
490
492
|
domainName: customDomain,
|
|
491
493
|
});
|
|
492
494
|
}
|
|
@@ -494,7 +496,7 @@ interface ImportMeta {
|
|
|
494
496
|
hostedZone = customDomain.cdk.hostedZone;
|
|
495
497
|
}
|
|
496
498
|
else if (typeof customDomain.hostedZone === "string") {
|
|
497
|
-
hostedZone =
|
|
499
|
+
hostedZone = HostedZone.fromLookup(this, "HostedZone", {
|
|
498
500
|
domainName: customDomain.hostedZone,
|
|
499
501
|
});
|
|
500
502
|
}
|
|
@@ -503,7 +505,7 @@ interface ImportMeta {
|
|
|
503
505
|
if (customDomain.isExternalDomain === true) {
|
|
504
506
|
return;
|
|
505
507
|
}
|
|
506
|
-
hostedZone =
|
|
508
|
+
hostedZone = HostedZone.fromLookup(this, "HostedZone", {
|
|
507
509
|
domainName: customDomain.domainName,
|
|
508
510
|
});
|
|
509
511
|
}
|
|
@@ -564,10 +566,10 @@ interface ImportMeta {
|
|
|
564
566
|
const recordProps = {
|
|
565
567
|
recordName,
|
|
566
568
|
zone: this.hostedZone,
|
|
567
|
-
target:
|
|
569
|
+
target: RecordTarget.fromAlias(new CloudFrontTarget(this.distribution)),
|
|
568
570
|
};
|
|
569
|
-
new
|
|
570
|
-
new
|
|
571
|
+
new ARecord(this, "AliasRecord", recordProps);
|
|
572
|
+
new AaaaRecord(this, "AliasRecordAAAA", recordProps);
|
|
571
573
|
// Create Alias redirect record
|
|
572
574
|
if (domainAlias) {
|
|
573
575
|
new HttpsRedirect(this, "Redirect", {
|