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.
@@ -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() {
@@ -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: true,
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 * as s3 from "aws-cdk-lib/aws-s3";
3
- import * as acm from "aws-cdk-lib/aws-certificatemanager";
4
- import * as route53 from "aws-cdk-lib/aws-route53";
5
- import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
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?: s3.BucketProps | s3.IBucket;
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: s3.Bucket;
305
- distribution: cloudfront.Distribution;
306
- hostedZone: route53.IHostedZone | undefined;
307
- certificate: acm.ICertificate | undefined;
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(): route53.IHostedZone | undefined;
328
+ protected lookupHostedZone(): IHostedZone | undefined;
329
329
  private createCertificate;
330
330
  protected createRoute53Records(): void;
331
331
  private getS3ContentReplaceValues;
@@ -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 * as s3 from "aws-cdk-lib/aws-s3";
9
- import * as s3Assets from "aws-cdk-lib/aws-s3-assets";
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 * as lambda from "aws-cdk-lib/aws-lambda";
12
- import * as route53 from "aws-cdk-lib/aws-route53";
13
- import * as route53Targets from "aws-cdk-lib/aws-route53-targets";
14
- import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
15
- import * as cfOrigins from "aws-cdk-lib/aws-cloudfront-origins";
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 s3Assets.Asset(this, `Asset${partId}`, {
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 s3Assets.Asset(this, `AssetFilenames`, {
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 s3.Bucket(this, "S3Bucket", {
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 lambda.Function(this, "S3Uploader", {
313
- code: lambda.Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
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: lambda.Runtime.PYTHON_3_7,
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 lambda.Function(this, "S3Handler", {
324
- code: lambda.Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
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: lambda.Runtime.PYTHON_3_7,
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 cloudfront.Distribution(this, "Distribution", {
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 cfOrigins.S3Origin(this.bucket),
418
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
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 = route53.HostedZone.fromLookup(this, "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 = route53.HostedZone.fromLookup(this, "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 = route53.HostedZone.fromLookup(this, "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: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
569
+ target: RecordTarget.fromAlias(new CloudFrontTarget(this.distribution)),
568
570
  };
569
- new route53.ARecord(this, "AliasRecord", recordProps);
570
- new route53.AaaaRecord(this, "AliasRecordAAAA", recordProps);
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", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.27",
3
+ "version": "2.0.29",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },