sst 2.30.4 → 2.32.0

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.
@@ -4,13 +4,11 @@ import fs from "fs";
4
4
  import crypto from "crypto";
5
5
  import { execSync } from "child_process";
6
6
  import { Construct } from "constructs";
7
- import { Token, Duration, RemovalPolicy, CustomResource, } from "aws-cdk-lib/core";
7
+ import { Token, RemovalPolicy, CustomResource } from "aws-cdk-lib/core";
8
8
  import { BlockPublicAccess, Bucket, } from "aws-cdk-lib/aws-s3";
9
9
  import { Asset } from "aws-cdk-lib/aws-s3-assets";
10
- import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";
11
10
  import { Function as CfFunction, FunctionCode as CfFunctionCode, FunctionEventType as CfFunctionEventType, ViewerProtocolPolicy, } from "aws-cdk-lib/aws-cloudfront";
12
11
  import { S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
13
- import { AwsCliLayer } from "aws-cdk-lib/lambda-layer-awscli";
14
12
  import { Stack } from "./Stack.js";
15
13
  import { Distribution } from "./Distribution.js";
16
14
  import { getBuildCmdEnvironment, buildErrorResponsesFor404ErrorPage, buildErrorResponsesForRedirectToIndex, } from "./BaseSite.js";
@@ -20,6 +18,8 @@ import { getParameterPath, } from "./util/functionBinding.js";
20
18
  import { gray } from "colorette";
21
19
  import { useProject } from "../project.js";
22
20
  import { createAppContext } from "./context.js";
21
+ import { Effect, Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
22
+ import { VisibleError } from "../error.js";
23
23
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
24
24
  /**
25
25
  * The `StaticSite` construct is a higher level CDK construct that makes it easy to create a static website.
@@ -49,11 +49,11 @@ export class StaticSite extends Construct {
49
49
  this.id = id;
50
50
  this.props = {
51
51
  path: ".",
52
- waitForInvalidation: false,
53
52
  ...props,
54
53
  };
55
54
  this.doNotDeploy =
56
55
  !stack.isActive || (app.mode === "dev" && !this.props.dev?.deploy);
56
+ this.validateDeprecatedFileOptions();
57
57
  this.generateViteTypes();
58
58
  useSites().add(stack.stackName, id, this.props);
59
59
  if (this.doNotDeploy) {
@@ -68,13 +68,14 @@ export class StaticSite extends Construct {
68
68
  // Build app
69
69
  this.buildApp();
70
70
  // Create S3 Deployment
71
- const cliLayer = new AwsCliLayer(this, "AwsCliLayer");
72
71
  const assets = this.createS3Assets();
73
72
  const filenamesAsset = this.bundleFilenamesAsset();
74
- const s3deployCR = this.createS3Deployment(cliLayer, assets, filenamesAsset);
73
+ const s3deployCR = this.createS3Deployment(assets, filenamesAsset);
75
74
  this.distribution.node.addDependency(s3deployCR);
76
75
  // Invalidate CloudFront
77
- this.distribution.createInvalidation(this.generateInvalidationId(assets));
76
+ this.distribution.createInvalidation({
77
+ version: this.generateInvalidationId(assets),
78
+ });
78
79
  });
79
80
  app.registerTypes(this);
80
81
  }
@@ -153,6 +154,12 @@ export class StaticSite extends Construct {
153
154
  },
154
155
  };
155
156
  }
157
+ validateDeprecatedFileOptions() {
158
+ // @ts-expect-error
159
+ if (this.props.fileOptions) {
160
+ throw new VisibleError(`In the "${this.node.id}" construct, the "fileOptions" property has been replaced by "assets.fileOptions". More details on upgrading - https://docs.sst.dev/upgrade-guide#upgrade-to-v2310`);
161
+ }
162
+ }
156
163
  generateViteTypes() {
157
164
  const { path: sitePath, environment } = this.props;
158
165
  // Build the path
@@ -295,81 +302,58 @@ interface ImportMeta {
295
302
  });
296
303
  }
297
304
  }
298
- createS3Deployment(cliLayer, assets, filenamesAsset) {
299
- const fileOptions = this.props.fileOptions ?? [
300
- {
301
- filters: [{ exclude: "*" }, { include: "*.html" }],
302
- cacheControl: "max-age=0,no-cache,no-store,must-revalidate",
303
- },
304
- {
305
- filters: [{ exclude: "*" }, { include: "*.js" }, { include: "*.css" }],
306
- cacheControl: "max-age=31536000,public,immutable",
307
- },
308
- ];
309
- // Create a Lambda function that will be doing the uploading
310
- const uploader = new Function(this, "S3Uploader", {
311
- code: Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
312
- layers: [cliLayer],
313
- runtime: Runtime.PYTHON_3_11,
314
- handler: "s3-upload.handler",
315
- timeout: Duration.minutes(15),
316
- memorySize: 1024,
317
- });
318
- this.bucket.grantReadWrite(uploader);
319
- assets.forEach((asset) => asset.grantRead(uploader));
320
- // Create the custom resource function
321
- const handler = new Function(this, "S3Handler", {
322
- code: Code.fromAsset(path.join(__dirname, "../support/base-site-custom-resource")),
323
- layers: [cliLayer],
324
- runtime: Runtime.PYTHON_3_11,
325
- handler: "s3-handler.handler",
326
- timeout: Duration.minutes(15),
327
- memorySize: 1024,
328
- environment: {
329
- UPLOADER_FUNCTION_NAME: uploader.functionName,
330
- },
305
+ createS3Deployment(assets, filenamesAsset) {
306
+ const stack = Stack.of(this);
307
+ const policy = new Policy(this, "S3UploaderPolicy", {
308
+ statements: [
309
+ new PolicyStatement({
310
+ effect: Effect.ALLOW,
311
+ actions: ["lambda:InvokeFunction"],
312
+ resources: [stack.customResourceHandler.functionArn],
313
+ }),
314
+ new PolicyStatement({
315
+ effect: Effect.ALLOW,
316
+ actions: ["s3:ListBucket", "s3:PutObject", "s3:DeleteObject"],
317
+ resources: [this.bucket.bucketArn, `${this.bucket.bucketArn}/*`],
318
+ }),
319
+ new PolicyStatement({
320
+ effect: Effect.ALLOW,
321
+ actions: ["s3:GetObject"],
322
+ resources: [`${assets[0].bucket.bucketArn}/*`],
323
+ }),
324
+ ],
331
325
  });
332
- this.bucket.grantReadWrite(handler);
333
- filenamesAsset?.grantRead(handler);
334
- uploader.grantInvoke(handler);
335
- // Create custom resource
336
- return new CustomResource(this, "S3Deployment", {
337
- serviceToken: handler.functionArn,
338
- resourceType: "Custom::SSTBucketDeployment",
326
+ stack.customResourceHandler.role?.attachInlinePolicy(policy);
327
+ const resource = new CustomResource(this, "S3Uploader", {
328
+ serviceToken: stack.customResourceHandler.functionArn,
329
+ resourceType: "Custom::S3Uploader",
339
330
  properties: {
340
- Sources: assets.map((asset) => ({
341
- BucketName: asset.s3BucketName,
342
- ObjectKey: asset.s3ObjectKey,
331
+ sources: assets.map((asset) => ({
332
+ bucketName: asset.s3BucketName,
333
+ objectKey: asset.s3ObjectKey,
343
334
  })),
344
- DestinationBucketName: this.bucket.bucketName,
345
- Filenames: filenamesAsset && {
346
- BucketName: filenamesAsset.s3BucketName,
347
- ObjectKey: filenamesAsset.s3ObjectKey,
335
+ destinationBucketName: this.bucket.bucketName,
336
+ filenames: filenamesAsset && {
337
+ bucketName: filenamesAsset.s3BucketName,
338
+ objectKey: filenamesAsset.s3ObjectKey,
348
339
  },
349
- FileOptions: (fileOptions || []).map((o) => {
350
- const { filters, cacheControl, contentType, contentEncoding } = o;
351
- const { include, exclude } = o;
352
- return [
353
- ...(typeof exclude === "string" ? [exclude] : exclude ?? [])
354
- .map((entry) => ["--exclude", entry])
355
- .flat(2),
356
- ...(typeof include === "string" ? [include] : include ?? [])
357
- .map((entry) => ["--include", entry])
358
- .flat(2),
359
- ...(filters || [])
360
- .map((filter) => Object.entries(filter).map(([key, value]) => [
361
- `--${key}`,
362
- value,
363
- ]))
364
- .flat(2),
365
- cacheControl ? ["--cache-control", cacheControl] : [],
366
- contentType ? ["--content-type", contentType] : [],
367
- contentEncoding ? ["--content-encoding", contentEncoding] : [],
368
- ].flat();
369
- }),
370
- ReplaceValues: this.getS3ContentReplaceValues(),
340
+ textEncoding: this.props.assets?.textEncoding ?? "utf-8",
341
+ fileOptions: [
342
+ {
343
+ files: "**",
344
+ cacheControl: "max-age=0,no-cache,no-store,must-revalidate",
345
+ },
346
+ {
347
+ files: ["**/*.js", "**/*.css"],
348
+ cacheControl: "max-age=31536000,public,immutable",
349
+ },
350
+ ...(this.props.assets?.fileOptions || []),
351
+ ],
352
+ replaceValues: this.getS3ContentReplaceValues(),
371
353
  },
372
354
  });
355
+ resource.node.addDependency(policy);
356
+ return resource;
373
357
  }
374
358
  /////////////////////
375
359
  // CloudFront Distribution
@@ -6,7 +6,7 @@ import { execSync } from "child_process";
6
6
  import { Construct } from "constructs";
7
7
  import { Token, Duration, RemovalPolicy, CustomResource, } from "aws-cdk-lib/core";
8
8
  import * as s3 from "aws-cdk-lib/aws-s3";
9
- import { Role, Effect, PolicyStatement, CompositePrincipal, ServicePrincipal, ManagedPolicy, } from "aws-cdk-lib/aws-iam";
9
+ import { Role, Effect, PolicyStatement, CompositePrincipal, ServicePrincipal, ManagedPolicy, Policy, } from "aws-cdk-lib/aws-iam";
10
10
  import * as sqs from "aws-cdk-lib/aws-sqs";
11
11
  import * as logs from "aws-cdk-lib/aws-logs";
12
12
  import * as lambda from "aws-cdk-lib/aws-lambda";
@@ -518,81 +518,67 @@ export class NextjsSite extends Construct {
518
518
  }
519
519
  }
520
520
  createS3Deployment() {
521
- // Create a Lambda function that will be doing the uploading
522
- const uploader = new lambda.Function(this, "S3Uploader", {
523
- code: lambda.Code.fromAsset(path.join(__dirname, "../../support/base-site-custom-resource")),
524
- layers: [this.awsCliLayer],
525
- runtime: lambda.Runtime.PYTHON_3_7,
526
- handler: "s3-upload.handler",
527
- timeout: Duration.minutes(15),
528
- memorySize: 1024,
529
- });
530
- this.cdk.bucket.grantReadWrite(uploader);
531
- this.assets.forEach((asset) => asset.grantRead(uploader));
532
- // Create the custom resource function
533
- const handler = new lambda.Function(this, "S3Handler", {
534
- code: lambda.Code.fromAsset(path.join(__dirname, "../../support/base-site-custom-resource")),
535
- layers: [this.awsCliLayer],
536
- runtime: lambda.Runtime.PYTHON_3_7,
537
- handler: "s3-handler.handler",
538
- timeout: Duration.minutes(15),
539
- memorySize: 1024,
540
- environment: {
541
- UPLOADER_FUNCTION_NAME: uploader.functionName,
542
- },
521
+ const stack = Stack.of(this);
522
+ const policy = new Policy(this, "S3UploaderPolicy", {
523
+ statements: [
524
+ new PolicyStatement({
525
+ effect: Effect.ALLOW,
526
+ actions: ["lambda:InvokeFunction"],
527
+ resources: [stack.customResourceHandler.functionArn],
528
+ }),
529
+ new PolicyStatement({
530
+ effect: Effect.ALLOW,
531
+ actions: ["s3:ListBucket", "s3:PutObject", "s3:DeleteObject"],
532
+ resources: [
533
+ this.cdk.bucket.bucketArn,
534
+ `${this.cdk.bucket.bucketArn}/*`,
535
+ ],
536
+ }),
537
+ new PolicyStatement({
538
+ effect: Effect.ALLOW,
539
+ actions: ["s3:GetObject"],
540
+ resources: [`${this.assets[0].bucket.bucketArn}/*`],
541
+ }),
542
+ ],
543
543
  });
544
- this.cdk.bucket.grantReadWrite(handler);
545
- uploader.grantInvoke(handler);
546
- // Create custom resource
547
- const fileOptions = [
548
- {
549
- exclude: "*",
550
- include: "public/*",
551
- cacheControl: "public,max-age=31536000,must-revalidate",
552
- },
553
- {
554
- exclude: "*",
555
- include: "static/*",
556
- cacheControl: "public,max-age=31536000,must-revalidate",
557
- },
558
- {
559
- exclude: "*",
560
- include: "static-pages/*",
561
- cacheControl: "public,max-age=0,s-maxage=2678400,must-revalidate",
562
- },
563
- {
564
- exclude: "*",
565
- include: "_next/data/*",
566
- cacheControl: "public,max-age=0,s-maxage=2678400,must-revalidate",
567
- },
568
- {
569
- exclude: "*",
570
- include: "_next/static/*",
571
- cacheControl: "public,max-age=31536000,immutable",
572
- },
573
- ];
574
- return new CustomResource(this, "S3Deployment", {
575
- serviceToken: handler.functionArn,
576
- resourceType: "Custom::SSTBucketDeployment",
544
+ stack.customResourceHandler.role?.attachInlinePolicy(policy);
545
+ const resource = new CustomResource(this, "S3Uploader", {
546
+ serviceToken: stack.customResourceHandler.functionArn,
547
+ resourceType: "Custom::S3Uploader",
577
548
  properties: {
578
- Sources: this.assets.map((asset) => ({
579
- BucketName: asset.s3BucketName,
580
- ObjectKey: asset.s3ObjectKey,
549
+ sources: this.assets.map((asset) => ({
550
+ bucketName: asset.s3BucketName,
551
+ objectKey: asset.s3ObjectKey,
581
552
  })),
582
- DestinationBucketName: this.cdk.bucket.bucketName,
583
- FileOptions: (fileOptions || []).map(({ exclude, include, cacheControl }) => {
584
- return [
585
- "--exclude",
586
- exclude,
587
- "--include",
588
- include,
589
- "--cache-control",
590
- cacheControl,
591
- ];
592
- }),
593
- ReplaceValues: this.getS3ContentReplaceValues(),
553
+ destinationBucketName: this.cdk.bucket.bucketName,
554
+ textEncoding: "UTF-8",
555
+ fileOptions: [
556
+ {
557
+ files: "/public/**",
558
+ cacheControl: "public,max-age=31536000,must-revalidate",
559
+ },
560
+ {
561
+ files: "/static/**",
562
+ cacheControl: "public,max-age=31536000,must-revalidate",
563
+ },
564
+ {
565
+ files: "/static-pages/**",
566
+ cacheControl: "public,max-age=0,s-maxage=2678400,must-revalidate",
567
+ },
568
+ {
569
+ files: "/_next/data/**",
570
+ cacheControl: "public,max-age=0,s-maxage=2678400,must-revalidate",
571
+ },
572
+ {
573
+ files: "/_next/static/**",
574
+ cacheControl: "public,max-age=31536000,immutable",
575
+ },
576
+ ],
577
+ replaceValues: this.getS3ContentReplaceValues(),
594
578
  },
595
579
  });
580
+ resource.node.addDependency(policy);
581
+ return resource;
596
582
  }
597
583
  /////////////////////
598
584
  // Build App
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.30.4",
4
+ "version": "2.32.0",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -73,7 +73,7 @@
73
73
  "express": "^4.18.2",
74
74
  "fast-jwt": "^3.1.1",
75
75
  "get-port": "^6.1.2",
76
- "glob": "^8.0.3",
76
+ "glob": "^10.0.0",
77
77
  "graphql": "*",
78
78
  "graphql-yoga": "^3.9.0",
79
79
  "immer": "9",
@@ -107,20 +107,21 @@
107
107
  "@tsconfig/node16": "^1.0.3",
108
108
  "@tsconfig/node18": "^18.2.2",
109
109
  "@types/adm-zip": "^0.5.0",
110
+ "@types/async": "^3.2.22",
110
111
  "@types/aws-iot-device-sdk": "^2.2.4",
111
112
  "@types/aws-lambda": "^8.10.108",
112
113
  "@types/babel__core": "^7.1.20",
113
114
  "@types/babel__generator": "^7.6.4",
114
115
  "@types/cross-spawn": "^6.0.2",
115
116
  "@types/express": "^4.17.14",
116
- "@types/glob": "^8.0.0",
117
117
  "@types/node": "^18.11.9",
118
118
  "@types/react": "^17.0.33",
119
119
  "@types/uuid": "^8.3.4",
120
120
  "@types/ws": "^8.5.3",
121
121
  "@types/yargs": "^17.0.13",
122
122
  "archiver": "^5.3.1",
123
- "astro-sst": "2.30.4",
123
+ "astro-sst": "2.32.0",
124
+ "async": "^3.2.4",
124
125
  "tsx": "^3.12.1",
125
126
  "typescript": "^5.2.2",
126
127
  "vitest": "^0.33.0"