sst 2.0.12 → 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.
@@ -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.12",
3
+ "version": "2.0.13",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/sst.mjs CHANGED
@@ -4228,11 +4228,16 @@ async function deploy(stack) {
4228
4228
  const deployment = new CloudFormationDeployments2({
4229
4229
  sdkProvider: provider
4230
4230
  });
4231
+ const stackTags = Object.entries(stack.tags ?? {}).map(([Key, Value]) => ({
4232
+ Key,
4233
+ Value
4234
+ }));
4231
4235
  try {
4232
4236
  await addInUseExports(stack);
4233
4237
  const result = await deployment.deployStack({
4234
4238
  stack,
4235
4239
  quiet: true,
4240
+ tags: stackTags,
4236
4241
  deploymentMethod: {
4237
4242
  method: "direct"
4238
4243
  }
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
  },