sst 2.23.3 → 2.23.5

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.
@@ -1,5 +1,6 @@
1
- const PACKAGE_MATCH = ["aws-cdk", "@aws-cdk"];
1
+ import { VisibleError } from "../../error.js";
2
2
  const FIELDS = ["dependencies", "devDependencies"];
3
+ const SST_PKGS = ["sst", "astro-sst", "svelte-kit-sst", "solid-start-sst"];
3
4
  export const update = (program) => program.command("update [version]", "Update your SST and CDK packages", (yargs) => yargs.positional("version", {
4
5
  type: "string",
5
6
  describe: "Optionally specify a version to update to",
@@ -9,7 +10,42 @@ export const update = (program) => program.command("update [version]", "Update y
9
10
  const { fetch } = await import("undici");
10
11
  const { useProject } = await import("../../project.js");
11
12
  const { Colors } = await import("../colors.js");
12
- async function find(dir) {
13
+ const project = useProject();
14
+ const files = await findAllPackageJson(project.paths.root);
15
+ const metadata = await fetch(`https://registry.npmjs.org/sst/${args.version || "latest"}`).then((resp) => resp.json());
16
+ const allChanges = new Map();
17
+ const allOldPackages = new Map();
18
+ // Update all package.json files
19
+ await Promise.all(files.map(updatePackageJson));
20
+ // Print status
21
+ if (allOldPackages.size > 0) {
22
+ for (const [file, pkgs] of allOldPackages.entries()) {
23
+ Colors.line(Colors.danger(`✖ `), Colors.bold.dim(path.relative(project.paths.root, file)));
24
+ for (const [pkg, version] of pkgs) {
25
+ Colors.line(Colors.dim(` ${pkg}@${version}`));
26
+ }
27
+ }
28
+ Colors.gap();
29
+ throw new VisibleError("We've detected AWS CDK v1 dependencies in your package.json. SST requires CDK v2. Please update to CDK v2 dependencies, and then execute `sst update`. Refer to the official AWS CDK migration documentation — https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html#migrating-v2-v1-upgrade");
30
+ }
31
+ // Print status
32
+ if (allChanges.size === 0) {
33
+ Colors.line(Colors.success(`✔ `), `Already using v${metadata.version}`);
34
+ return;
35
+ }
36
+ for (const [file, pkgs] of allChanges.entries()) {
37
+ Colors.line(Colors.success(`✔ `), Colors.bold.dim(path.relative(project.paths.root, file)));
38
+ for (const [pkg, version] of pkgs) {
39
+ Colors.line(Colors.dim(` ${pkg}@${version}`));
40
+ }
41
+ }
42
+ Colors.gap();
43
+ Colors.line(`${Colors.primary(`➜`)} ${Colors.warning("Make sure to run: npm install (or pnpm install, or yarn)")}`);
44
+ process.exit(0);
45
+ /////////////
46
+ // Helpers
47
+ /////////////
48
+ async function findAllPackageJson(dir) {
13
49
  const children = await fs.readdir(dir);
14
50
  const tasks = children.map(async (item) => {
15
51
  if (item === "node_modules")
@@ -22,69 +58,53 @@ export const update = (program) => program.command("update [version]", "Update y
22
58
  return [full];
23
59
  const stat = await fs.stat(full);
24
60
  if (stat.isDirectory())
25
- return find(full);
61
+ return findAllPackageJson(full);
26
62
  return [];
27
63
  });
28
64
  return (await Promise.all(tasks)).flat();
29
65
  }
30
- const project = useProject();
31
- const files = await find(project.paths.root);
32
- const metadata = await fetch(`https://registry.npmjs.org/sst/${args.version || "latest"}`).then((resp) => resp.json());
33
- const results = new Map();
34
- const tasks = files.map(async (file) => {
66
+ async function updatePackageJson(file) {
67
+ const changes = new Set();
68
+ const oldPackages = new Set();
35
69
  const data = await fs.readFile(file).then((x) => x.toString());
36
- // Note: preserve ending new line characters in package.json
37
- const tailingNewline = data.match(/\r?\n$/)?.[0];
38
70
  const json = JSON.parse(data);
71
+ // Update versions
39
72
  for (const field of FIELDS) {
40
73
  const deps = json[field];
41
74
  for (const [pkg, existing] of Object.entries(deps || {})) {
42
75
  const desired = (() => {
43
- if ([
44
- "sst",
45
- "astro-sst",
46
- "svelte-kit-sst",
47
- "solid-start-sst",
48
- ].includes(pkg)) {
76
+ if (SST_PKGS.includes(pkg)) {
49
77
  return metadata.version;
50
78
  }
51
79
  else if (pkg === "constructs") {
52
80
  return metadata.dependencies.constructs;
53
81
  }
54
- else if (pkg.startsWith("aws-cdk") ||
55
- pkg.startsWith("@aws-cdk")) {
56
- return pkg.endsWith("alpha")
57
- ? metadata.dependencies["@aws-cdk/aws-apigatewayv2-alpha"]
58
- : metadata.dependencies["aws-cdk-lib"];
82
+ else if (pkg === "aws-cdk-lib") {
83
+ return metadata.dependencies["aws-cdk-lib"];
84
+ }
85
+ else if (pkg.startsWith("@aws-cdk/aws-")) {
86
+ if (!pkg.endsWith("-alpha")) {
87
+ oldPackages.add([pkg, existing]);
88
+ return;
89
+ }
90
+ return metadata.dependencies["@aws-cdk/aws-apigatewayv2-alpha"];
59
91
  }
60
92
  })();
61
93
  if (!desired || existing === desired)
62
94
  continue;
63
- let arr = results.get(file);
64
- if (!arr) {
65
- arr = new Set();
66
- results.set(file, arr);
67
- }
68
- arr.add([pkg, desired]);
95
+ changes.add([pkg, desired]);
69
96
  deps[pkg] = desired;
70
97
  }
71
98
  }
72
- if (results.has(file)) {
99
+ // Write to package.json
100
+ if (changes.size > 0) {
101
+ // note: preserve ending new line characters in package.json
102
+ const tailingNewline = data.match(/\r?\n$/)?.[0];
73
103
  await fs.writeFile(file, `${JSON.stringify(json, null, 2)}${tailingNewline ?? ""}`);
104
+ allChanges.set(file, changes);
74
105
  }
75
- });
76
- await Promise.all(tasks);
77
- if (results.size === 0) {
78
- Colors.line(Colors.success(`✔ `), `Already using v${metadata.version}`);
79
- return;
80
- }
81
- for (const [file, pkgs] of results.entries()) {
82
- Colors.line(Colors.success(`✔ `), Colors.bold.dim(path.relative(project.paths.root, file)));
83
- for (const [pkg, version] of pkgs) {
84
- Colors.line(Colors.dim(` ${pkg}@${version}`));
106
+ if (oldPackages.size > 0) {
107
+ allOldPackages.set(file, oldPackages);
85
108
  }
86
109
  }
87
- Colors.gap();
88
- Colors.line(`${Colors.primary(`➜`)} ${Colors.warning("Make sure to run: npm install (or pnpm install, or yarn)")}`);
89
- process.exit(0);
90
110
  });
@@ -18,7 +18,7 @@ import { createAppContext } from "./context.js";
18
18
  import { useWarning } from "./util/warning.js";
19
19
  import { Architecture, AssetCode, Code, Function as CDKFunction, FunctionUrlAuthType, Handler as CDKHandler, LayerVersion, Runtime as CDKRuntime, Tracing, } from "aws-cdk-lib/aws-lambda";
20
20
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
21
- import { Token, Size as CDKSize, Duration as CDKDuration, } from "aws-cdk-lib/core";
21
+ import { Token, Size as CDKSize, Duration as CDKDuration, IgnoreMode, } from "aws-cdk-lib/core";
22
22
  import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
23
23
  import { StringParameter } from "aws-cdk-lib/aws-ssm";
24
24
  import { Platform } from "aws-cdk-lib/aws-ecr-assets";
@@ -202,6 +202,8 @@ export class Function extends CDKFunction {
202
202
  ...(props.container?.file
203
203
  ? { file: props.container.file }
204
204
  : {}),
205
+ exclude: [".sst"],
206
+ ignoreMode: IgnoreMode.GLOB,
205
207
  }),
206
208
  handler: CDKHandler.FROM_IMAGE,
207
209
  runtime: CDKRuntime.FROM_IMAGE,
package/constructs/Job.js CHANGED
@@ -2,7 +2,7 @@ import url from "url";
2
2
  import path from "path";
3
3
  import fs from "fs/promises";
4
4
  import { Construct } from "constructs";
5
- import { Duration as CdkDuration } from "aws-cdk-lib/core";
5
+ import { Duration as CdkDuration, IgnoreMode } from "aws-cdk-lib/core";
6
6
  import { Platform } from "aws-cdk-lib/aws-ecr-assets";
7
7
  import { PolicyStatement, Effect } from "aws-cdk-lib/aws-iam";
8
8
  import { AssetCode, Code, Runtime, Function as CdkFunction, } from "aws-cdk-lib/aws-lambda";
@@ -213,6 +213,8 @@ export class Job extends Construct {
213
213
  ? Platform.custom("linux/arm64")
214
214
  : Platform.custom("linux/amd64"),
215
215
  file: container?.file,
216
+ exclude: [".sst"],
217
+ ignoreMode: IgnoreMode.GLOB,
216
218
  });
217
219
  image.repository?.grantPull(this.job.role);
218
220
  const project = this.job.node.defaultChild;
@@ -3,7 +3,7 @@ import { DistributionDomainProps } from "./Distribution.js";
3
3
  import { SSTConstruct } from "./Construct.js";
4
4
  import { Permissions } from "./util/permission.js";
5
5
  import { FunctionBindingProps } from "./util/functionBinding.js";
6
- import { ISecurityGroup, IVpc, SubnetSelection } from "aws-cdk-lib/aws-ec2";
6
+ import { IVpc } from "aws-cdk-lib/aws-ec2";
7
7
  import { Cluster, ContainerDefinitionOptions } from "aws-cdk-lib/aws-ecs";
8
8
  import { RetentionDays } from "aws-cdk-lib/aws-logs";
9
9
  declare const supportedCpus: {
@@ -275,40 +275,6 @@ export interface ServiceProps {
275
275
  * ```
276
276
  */
277
277
  vpc?: IVpc;
278
- /**
279
- * Where to place the network interfaces within the VPC.
280
- * @default All private subnets.
281
- * @example
282
- * ```js
283
- * import { SubnetType } from "aws-cdk-lib/aws-ec2";
284
- *
285
- * {
286
- * cdk: {
287
- * vpc,
288
- * vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS }
289
- * }
290
- * }
291
- * ```
292
- */
293
- vpcSubnets?: SubnetSelection;
294
- /**
295
- * The list of security groups to associate with the Job's network interfaces.
296
- * @default A new security group is created.
297
- * @example
298
- * ```js
299
- * import { SecurityGroup } from "aws-cdk-lib/aws-ec2";
300
- *
301
- * {
302
- * cdk: {
303
- * vpc,
304
- * securityGroups: [
305
- * new SecurityGroup(stack, "MyJobSG", { vpc })
306
- * ]
307
- * }
308
- * }
309
- * ```
310
- */
311
- securityGroups?: ISecurityGroup[];
312
278
  };
313
279
  }
314
280
  type ServiceNormalizedProps = ServiceProps & {
@@ -6,7 +6,7 @@ import { execAsync } from "../util/process.js";
6
6
  import { existsAsync } from "../util/fs.js";
7
7
  import { Colors } from "../cli/colors.js";
8
8
  import { Construct } from "constructs";
9
- import { Duration as CdkDuration } from "aws-cdk-lib/core";
9
+ import { Duration as CdkDuration, IgnoreMode } from "aws-cdk-lib/core";
10
10
  import { Role, Effect, PolicyStatement, AccountPrincipal, ServicePrincipal, CompositePrincipal, } from "aws-cdk-lib/aws-iam";
11
11
  import { ViewerProtocolPolicy, AllowedMethods, CachedMethods, CachePolicy, CacheQueryStringBehavior, CacheHeaderBehavior, CacheCookieBehavior, OriginProtocolPolicy, OriginRequestPolicy, } from "aws-cdk-lib/aws-cloudfront";
12
12
  import { HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
@@ -20,7 +20,7 @@ import { bindEnvironment, bindPermissions, getParameterPath, getReferencedSecret
20
20
  import { useProject } from "../project.js";
21
21
  import { Vpc, } from "aws-cdk-lib/aws-ec2";
22
22
  import { AwsLogDriver, Cluster, FargateTaskDefinition, ContainerImage, FargateService, } from "aws-cdk-lib/aws-ecs";
23
- import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
23
+ import { LogGroup, LogRetention, RetentionDays } from "aws-cdk-lib/aws-logs";
24
24
  import { Platform } from "aws-cdk-lib/aws-ecr-assets";
25
25
  import { ApplicationLoadBalancer, } from "aws-cdk-lib/aws-elasticloadbalancingv2";
26
26
  import { createAppContext } from "./context.js";
@@ -360,16 +360,19 @@ export class Service extends Construct {
360
360
  const { cdk } = this.props;
361
361
  return (cdk?.vpc ??
362
362
  new Vpc(this, "Vpc", {
363
- natGateways: 0,
363
+ natGateways: 1,
364
364
  }));
365
365
  }
366
366
  createService(vpc) {
367
367
  const { cpu, memory, port, logRetention, cdk } = this.props;
368
368
  const app = this.node.root;
369
369
  const clusterName = app.logicalPrefixedName(this.node.id);
370
- const logGroup = new LogGroup(this, "LogGroup", {
370
+ const logGroup = new LogRetention(this, "LogRetention", {
371
371
  logGroupName: `/sst/service/${clusterName}`,
372
372
  retention: RetentionDays[logRetention.toUpperCase()],
373
+ logRetentionRetryOptions: {
374
+ maxRetries: 100,
375
+ },
373
376
  });
374
377
  const cluster = new Cluster(this, "Cluster", {
375
378
  clusterName,
@@ -382,7 +385,7 @@ export class Service extends Construct {
382
385
  });
383
386
  const container = taskDefinition.addContainer("Container", {
384
387
  logging: new AwsLogDriver({
385
- logGroup,
388
+ logGroup: LogGroup.fromLogGroupArn(this, "LogGroup", logGroup.logGroupArn),
386
389
  streamPrefix: "service",
387
390
  }),
388
391
  portMappings: [{ containerPort: port }],
@@ -580,6 +583,8 @@ export class Service extends Construct {
580
583
  const image = ContainerImage.fromAsset(this.props.path, {
581
584
  platform: Platform.LINUX_AMD64,
582
585
  file: dockerfile,
586
+ exclude: [".sst"],
587
+ ignoreMode: IgnoreMode.GLOB,
583
588
  });
584
589
  const cfnTask = taskDefinition.node.defaultChild;
585
590
  cfnTask.addPropertyOverride("ContainerDefinitions.0.Image", image.bind(this, container).imageName);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.23.3",
4
+ "version": "2.23.5",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },