sst 2.0.11 → 2.0.13

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.
@@ -57,7 +57,11 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
57
57
  return result;
58
58
  })();
59
59
  const target = assembly.stacks.filter((s) => !args.filter ||
60
- s.stackName.toLowerCase().includes(args.filter.toLowerCase()));
60
+ s.id
61
+ .toLowerCase()
62
+ .replace(project.config.name.toLowerCase(), "")
63
+ .replace(project.config.stage.toLowerCase(), "")
64
+ .includes(args.filter.toLowerCase()));
61
65
  if (!target.length) {
62
66
  Colors.line(`No stacks found matching ${blue(args.filter)}`);
63
67
  process.exit(1);
@@ -30,7 +30,11 @@ export const remove = (program) => program.command("remove [filter]", "Remove yo
30
30
  });
31
31
  })();
32
32
  const target = assembly.stacks.filter((s) => !args.filter ||
33
- s.stackName.toLowerCase().includes(args.filter.toLowerCase()));
33
+ s.id
34
+ .toLowerCase()
35
+ .replace(project.config.name.toLowerCase(), "")
36
+ .replace(project.config.stage.toLowerCase(), "")
37
+ .includes(args.filter.toLowerCase()));
34
38
  if (!target.length) {
35
39
  console.log(`No stacks found matching ${blue(args.filter)}`);
36
40
  process.exit(1);
package/cli/ui/deploy.js CHANGED
@@ -71,7 +71,7 @@ export function printDeploymentResults(assembly, results, remove) {
71
71
  const success = Object.entries(results).filter(([_stack, result]) => Stacks.isSuccess(result.status));
72
72
  if (success.length) {
73
73
  Colors.gap();
74
- Colors.line(Colors.success(`✔`), Colors.bold(remove ? ` Removed:` : ` Deployed:`));
74
+ Colors.line(Colors.success(`✔`), Colors.bold(remove ? ` Removed:` : ` Deployed:`));
75
75
  for (const [stack, result] of success) {
76
76
  const outputs = Object.entries(result.outputs).filter(([key, _]) => !key.includes("SstSiteEnv"));
77
77
  Colors.line(` ${Colors.dim(stackNameToId(stack))}`);
@@ -140,7 +140,6 @@ export declare class Job extends Construct implements SSTConstruct {
140
140
  private readonly localId;
141
141
  private readonly props;
142
142
  private readonly job;
143
- private readonly isLiveDevEnabled;
144
143
  readonly _jobInvoker: Function;
145
144
  constructor(scope: Construct, id: string, props: JobProps);
146
145
  getConstructMetadata(): {
package/constructs/Job.js CHANGED
@@ -3,9 +3,9 @@ import url from "url";
3
3
  import path from "path";
4
4
  import fs from "fs/promises";
5
5
  import { Construct } from "constructs";
6
- import * as iam from "aws-cdk-lib/aws-iam";
7
- import * as lambda from "aws-cdk-lib/aws-lambda";
8
- import * as codebuild from "aws-cdk-lib/aws-codebuild";
6
+ import { PolicyStatement, Effect } from "aws-cdk-lib/aws-iam";
7
+ import { AssetCode } from "aws-cdk-lib/aws-lambda";
8
+ import { Project, LinuxBuildImage, BuildSpec, ComputeType, } from "aws-cdk-lib/aws-codebuild";
9
9
  import { Stack } from "./Stack.js";
10
10
  import { Function, useFunctions } from "./Function.js";
11
11
  import { toCdkDuration } from "./util/duration.js";
@@ -37,7 +37,6 @@ export class Job extends Construct {
37
37
  localId;
38
38
  props;
39
39
  job;
40
- isLiveDevEnabled;
41
40
  _jobInvoker;
42
41
  constructor(scope, id, props) {
43
42
  super(scope, props.cdk?.id || id);
@@ -53,9 +52,9 @@ export class Job extends Construct {
53
52
  .replace(/\$/g, "-")
54
53
  .replace(/\//g, "-")
55
54
  .replace(/\./g, "-");
56
- this.isLiveDevEnabled = this.props.enableLiveDev === false ? false : true;
55
+ const isLiveDevEnabled = app.local && (this.props.enableLiveDev === false ? false : true);
57
56
  this.job = this.createCodeBuildProject();
58
- if (app.local && this.isLiveDevEnabled) {
57
+ if (isLiveDevEnabled) {
59
58
  this._jobInvoker = this.createLocalInvoker();
60
59
  }
61
60
  else {
@@ -129,7 +128,7 @@ export class Job extends Construct {
129
128
  }
130
129
  createCodeBuildProject() {
131
130
  const app = this.node.root;
132
- return new codebuild.Project(this, "JobProject", {
131
+ return new Project(this, "JobProject", {
133
132
  vpc: this.props.cdk?.vpc,
134
133
  projectName: app.logicalPrefixedName(this.node.id),
135
134
  environment: {
@@ -139,7 +138,7 @@ export class Job extends Construct {
139
138
  // purpose of this demo, I use STANDARD_5_0. It takes 30s to boot.
140
139
  //buildImage: codebuild.LinuxBuildImage.STANDARD_6_0,
141
140
  //buildImage: codebuild.LinuxBuildImage.STANDARD_5_0,
142
- buildImage: codebuild.LinuxBuildImage.fromDockerRegistry("amazon/aws-lambda-nodejs:16"),
141
+ buildImage: LinuxBuildImage.fromDockerRegistry("amazon/aws-lambda-nodejs:16"),
143
142
  computeType: this.normalizeMemorySize(this.props.memorySize || "3 GB"),
144
143
  },
145
144
  environmentVariables: {
@@ -148,7 +147,7 @@ export class Job extends Construct {
148
147
  SST_SSM_PREFIX: { value: useProject().config.ssmPrefix },
149
148
  },
150
149
  timeout: this.normalizeTimeout(this.props.timeout || "8 hours"),
151
- buildSpec: codebuild.BuildSpec.fromObject({
150
+ buildSpec: BuildSpec.fromObject({
152
151
  version: "0.2",
153
152
  phases: {
154
153
  build: {
@@ -163,54 +162,40 @@ export class Job extends Construct {
163
162
  buildCodeBuildProjectCode() {
164
163
  const app = this.node.root;
165
164
  // Handle remove (ie. sst remove)
166
- if (app.mode !== "deploy") {
167
- // do nothing
168
- }
169
- // Handle build
170
- else {
171
- useDeferredTasks().add(async () => {
172
- // Build function
173
- /*
174
- const bundled = await Runtime.Handler.bundle({
175
- id: this.localId,
176
- root: app.appPath,
177
- handler,
178
- runtime: "nodejs16.x",
179
- srcPath,
180
- bundle
181
- })!;
182
- */
183
- // TODO: Fix
184
- const bundle = await useRuntimeHandlers().build(this.node.addr, "deploy");
185
- // handle copy files
186
- // create wrapper that calls the handler
187
- if (bundle.type === "error")
188
- throw new Error(`Failed to build job "${this.props.handler}"`);
189
- const parsed = path.parse(bundle.handler);
190
- await fs.writeFile(path.join(bundle.out, "handler-wrapper.js"), [
191
- `console.log("")`,
192
- `console.log("//////////////////////")`,
193
- `console.log("// Start of the job //")`,
194
- `console.log("//////////////////////")`,
195
- `console.log("")`,
196
- `import { ${parsed.ext.substring(1)} } from "./${path.join(parsed.dir, parsed.name)}.mjs";`,
197
- `const event = JSON.parse(process.env.SST_PAYLOAD);`,
198
- `const result = await ${parsed.name}(event);`,
199
- `console.log("")`,
200
- `console.log("----------------------")`,
201
- `console.log("")`,
202
- `console.log("Result:", result);`,
203
- `console.log("")`,
204
- `console.log("//////////////////////")`,
205
- `console.log("// End of the job //")`,
206
- `console.log("//////////////////////")`,
207
- `console.log("")`,
208
- ].join("\n"));
209
- const code = lambda.AssetCode.fromAsset(bundle.out);
210
- this.updateCodeBuildProjectCode(code, "handler-wrapper.js");
211
- // This should always be true b/c runtime is always Node.js
212
- });
213
- }
165
+ if (app.mode === "remove")
166
+ return;
167
+ useDeferredTasks().add(async () => {
168
+ // Build function
169
+ const bundle = await useRuntimeHandlers().build(this.node.addr, "deploy");
170
+ // create wrapper that calls the handler
171
+ if (bundle.type === "error")
172
+ throw new Error(`Failed to build job "${this.props.handler}"`);
173
+ const parsed = path.parse(bundle.handler);
174
+ const importName = parsed.ext.substring(1);
175
+ const importPath = `./${path.join(parsed.dir, parsed.name)}.mjs`;
176
+ await fs.writeFile(path.join(bundle.out, "handler-wrapper.mjs"), [
177
+ `console.log("")`,
178
+ `console.log("//////////////////////")`,
179
+ `console.log("// Start of the job //")`,
180
+ `console.log("//////////////////////")`,
181
+ `console.log("")`,
182
+ `import { ${importName} } from "${importPath}";`,
183
+ `const event = JSON.parse(process.env.SST_PAYLOAD);`,
184
+ `const result = await ${importName}(event);`,
185
+ `console.log("")`,
186
+ `console.log("----------------------")`,
187
+ `console.log("")`,
188
+ `console.log("Result:", result);`,
189
+ `console.log("")`,
190
+ `console.log("//////////////////////")`,
191
+ `console.log("// End of the job //")`,
192
+ `console.log("//////////////////////")`,
193
+ `console.log("")`,
194
+ ].join("\n"));
195
+ const code = AssetCode.fromAsset(bundle.out);
196
+ this.updateCodeBuildProjectCode(code, "handler-wrapper.mjs");
197
+ // This should always be true b/c runtime is always Node.js
198
+ });
214
199
  }
215
200
  updateCodeBuildProjectCode(code, script) {
216
201
  // Update job's commands
@@ -228,9 +213,9 @@ export class Job extends Construct {
228
213
  ].join("\n"),
229
214
  };
230
215
  this.attachPermissions([
231
- new iam.PolicyStatement({
216
+ new PolicyStatement({
232
217
  actions: ["s3:*"],
233
- effect: iam.Effect.ALLOW,
218
+ effect: Effect.ALLOW,
234
219
  resources: [
235
220
  `arn:${Stack.of(this).partition}:s3:::${codeConfig.s3Location?.bucketName}/${codeConfig.s3Location?.objectKey}`,
236
221
  ],
@@ -259,15 +244,15 @@ export class Job extends Construct {
259
244
  createCodeBuildInvoker() {
260
245
  const fn = new Function(this, this.node.id, {
261
246
  handler: path.join(__dirname, "../support/job-invoker/index.main"),
262
- runtime: "nodejs16.x",
247
+ runtime: "nodejs18.x",
263
248
  timeout: 10,
264
249
  memorySize: 1024,
265
250
  environment: {
266
251
  PROJECT_NAME: this.job.projectName,
267
252
  },
268
253
  permissions: [
269
- new iam.PolicyStatement({
270
- effect: iam.Effect.ALLOW,
254
+ new PolicyStatement({
255
+ effect: Effect.ALLOW,
271
256
  actions: ["codebuild:StartBuild"],
272
257
  resources: [this.job.projectArn],
273
258
  }),
@@ -289,9 +274,9 @@ export class Job extends Construct {
289
274
  // Bind permissions
290
275
  const permissions = bindPermissions(c);
291
276
  Object.entries(permissions).forEach(([action, resources]) => this.attachPermissionsForCodeBuild([
292
- new iam.PolicyStatement({
277
+ new PolicyStatement({
293
278
  actions: [action],
294
- effect: iam.Effect.ALLOW,
279
+ effect: Effect.ALLOW,
295
280
  resources,
296
281
  }),
297
282
  ]));
@@ -308,16 +293,16 @@ export class Job extends Construct {
308
293
  }
309
294
  normalizeMemorySize(memorySize) {
310
295
  if (memorySize === "3 GB") {
311
- return codebuild.ComputeType.SMALL;
296
+ return ComputeType.SMALL;
312
297
  }
313
298
  else if (memorySize === "7 GB") {
314
- return codebuild.ComputeType.MEDIUM;
299
+ return ComputeType.MEDIUM;
315
300
  }
316
301
  else if (memorySize === "15 GB") {
317
- return codebuild.ComputeType.LARGE;
302
+ return ComputeType.LARGE;
318
303
  }
319
304
  else if (memorySize === "145 GB") {
320
- return codebuild.ComputeType.X2_LARGE;
305
+ return ComputeType.X2_LARGE;
321
306
  }
322
307
  throw new Error(`Invalid memory size value for the ${this.node.id} Job.`);
323
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -793,7 +793,7 @@ var init_site_env = __esm({
793
793
  }
794
794
  });
795
795
 
796
- // ../../node_modules/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.es6.js
796
+ // ../../node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.es6.js
797
797
  var tslib_es6_exports = {};
798
798
  __export(tslib_es6_exports, {
799
799
  __assign: () => __assign,
@@ -807,6 +807,7 @@ __export(tslib_es6_exports, {
807
807
  __classPrivateFieldSet: () => __classPrivateFieldSet,
808
808
  __createBinding: () => __createBinding,
809
809
  __decorate: () => __decorate,
810
+ __esDecorate: () => __esDecorate,
810
811
  __exportStar: () => __exportStar,
811
812
  __extends: () => __extends,
812
813
  __generator: () => __generator,
@@ -815,8 +816,11 @@ __export(tslib_es6_exports, {
815
816
  __makeTemplateObject: () => __makeTemplateObject,
816
817
  __metadata: () => __metadata,
817
818
  __param: () => __param,
819
+ __propKey: () => __propKey,
818
820
  __read: () => __read,
819
821
  __rest: () => __rest,
822
+ __runInitializers: () => __runInitializers,
823
+ __setFunctionName: () => __setFunctionName,
820
824
  __spread: () => __spread,
821
825
  __spreadArray: () => __spreadArray,
822
826
  __spreadArrays: () => __spreadArrays,
@@ -858,6 +862,65 @@ function __param(paramIndex, decorator) {
858
862
  decorator(target, key, paramIndex);
859
863
  };
860
864
  }
865
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
866
+ function accept(f) {
867
+ if (f !== void 0 && typeof f !== "function")
868
+ throw new TypeError("Function expected");
869
+ return f;
870
+ }
871
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
872
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
873
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
874
+ var _, done = false;
875
+ for (var i = decorators.length - 1; i >= 0; i--) {
876
+ var context = {};
877
+ for (var p in contextIn)
878
+ context[p] = p === "access" ? {} : contextIn[p];
879
+ for (var p in contextIn.access)
880
+ context.access[p] = contextIn.access[p];
881
+ context.addInitializer = function(f) {
882
+ if (done)
883
+ throw new TypeError("Cannot add initializers after decoration has completed");
884
+ extraInitializers.push(accept(f || null));
885
+ };
886
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
887
+ if (kind === "accessor") {
888
+ if (result === void 0)
889
+ continue;
890
+ if (result === null || typeof result !== "object")
891
+ throw new TypeError("Object expected");
892
+ if (_ = accept(result.get))
893
+ descriptor.get = _;
894
+ if (_ = accept(result.set))
895
+ descriptor.set = _;
896
+ if (_ = accept(result.init))
897
+ initializers.push(_);
898
+ } else if (_ = accept(result)) {
899
+ if (kind === "field")
900
+ initializers.push(_);
901
+ else
902
+ descriptor[key] = _;
903
+ }
904
+ }
905
+ if (target)
906
+ Object.defineProperty(target, contextIn.name, descriptor);
907
+ done = true;
908
+ }
909
+ function __runInitializers(thisArg, initializers, value) {
910
+ var useValue = arguments.length > 2;
911
+ for (var i = 0; i < initializers.length; i++) {
912
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
913
+ }
914
+ return useValue ? value : void 0;
915
+ }
916
+ function __propKey(x) {
917
+ return typeof x === "symbol" ? x : "".concat(x);
918
+ }
919
+ function __setFunctionName(f, name, prefix) {
920
+ if (typeof name === "symbol")
921
+ name = name.description ? "[".concat(name.description, "]") : "";
922
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
923
+ }
861
924
  function __metadata(metadataKey, metadataValue) {
862
925
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
863
926
  return Reflect.metadata(metadataKey, metadataValue);
@@ -1077,7 +1140,7 @@ function __asyncDelegator(o) {
1077
1140
  }, i;
1078
1141
  function verb(n, f) {
1079
1142
  i[n] = o[n] ? function(v) {
1080
- return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
1143
+ return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v;
1081
1144
  } : f;
1082
1145
  }
1083
1146
  }
@@ -1147,7 +1210,7 @@ function __classPrivateFieldIn(state2, receiver) {
1147
1210
  }
1148
1211
  var extendStatics, __assign, __createBinding, __setModuleDefault;
1149
1212
  var init_tslib_es6 = __esm({
1150
- "../../node_modules/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.es6.js"() {
1213
+ "../../node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.es6.js"() {
1151
1214
  extendStatics = function(d, b) {
1152
1215
  extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
1153
1216
  d2.__proto__ = b2;
@@ -4165,11 +4228,16 @@ async function deploy(stack) {
4165
4228
  const deployment = new CloudFormationDeployments2({
4166
4229
  sdkProvider: provider
4167
4230
  });
4231
+ const stackTags = Object.entries(stack.tags ?? {}).map(([Key, Value]) => ({
4232
+ Key,
4233
+ Value
4234
+ }));
4168
4235
  try {
4169
4236
  await addInUseExports(stack);
4170
4237
  const result = await deployment.deployStack({
4171
4238
  stack,
4172
4239
  quiet: true,
4240
+ tags: stackTags,
4173
4241
  deploymentMethod: {
4174
4242
  method: "direct"
4175
4243
  }
@@ -5442,7 +5510,7 @@ function printDeploymentResults(assembly, results, remove4) {
5442
5510
  Colors.gap();
5443
5511
  Colors.line(
5444
5512
  Colors.success(`\u2714`),
5445
- Colors.bold(remove4 ? ` Removed:` : ` Deployed:`)
5513
+ Colors.bold(remove4 ? ` Removed:` : ` Deployed:`)
5446
5514
  );
5447
5515
  for (const [stack, result] of success) {
5448
5516
  const outputs = Object.entries(result.outputs).filter(
@@ -6722,7 +6790,7 @@ var deploy2 = (program2) => program2.command(
6722
6790
  return result;
6723
6791
  }();
6724
6792
  const target = assembly.stacks.filter(
6725
- (s) => !args.filter || s.stackName.toLowerCase().includes(args.filter.toLowerCase())
6793
+ (s) => !args.filter || s.id.toLowerCase().replace(project.config.name.toLowerCase(), "").replace(project.config.stage.toLowerCase(), "").includes(args.filter.toLowerCase())
6726
6794
  );
6727
6795
  if (!target.length) {
6728
6796
  Colors.line(`No stacks found matching ${blue4(args.filter)}`);
@@ -6804,7 +6872,7 @@ var remove2 = (program2) => program2.command(
6804
6872
  });
6805
6873
  }();
6806
6874
  const target = assembly.stacks.filter(
6807
- (s) => !args.filter || s.stackName.toLowerCase().includes(args.filter.toLowerCase())
6875
+ (s) => !args.filter || s.id.toLowerCase().replace(project.config.name.toLowerCase(), "").replace(project.config.stage.toLowerCase(), "").includes(args.filter.toLowerCase())
6808
6876
  );
6809
6877
  if (!target.length) {
6810
6878
  console.log(`No stacks found matching ${blue4(args.filter)}`);
package/stacks/deploy.js CHANGED
@@ -74,11 +74,16 @@ export async function deploy(stack) {
74
74
  const deployment = new CloudFormationDeployments({
75
75
  sdkProvider: provider,
76
76
  });
77
+ const stackTags = Object.entries(stack.tags ?? {}).map(([Key, Value]) => ({
78
+ Key,
79
+ Value,
80
+ }));
77
81
  try {
78
82
  await addInUseExports(stack);
79
83
  const result = await deployment.deployStack({
80
84
  stack: stack,
81
85
  quiet: true,
86
+ tags: stackTags,
82
87
  deploymentMethod: {
83
88
  method: "direct",
84
89
  },