sst 2.1.10 → 2.1.12

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.
package/config.js CHANGED
@@ -117,21 +117,32 @@ export var Config;
117
117
  .flat()
118
118
  .filter((f) => f.type === "Function")
119
119
  .filter((f) => f.data.secrets.includes(key));
120
- await Promise.all(filtered.map(async (f) => {
121
- const config = await lambda.send(new GetFunctionConfigurationCommand({
122
- FunctionName: f.data.arn,
123
- }));
124
- await lambda.send(new UpdateFunctionConfigurationCommand({
125
- FunctionName: f.data.arn,
126
- Environment: {
127
- Variables: {
128
- ...(config.Environment?.Variables || {}),
129
- [SECRET_UPDATED_AT_ENV]: Date.now().toString(),
120
+ const restarted = await Promise.all(filtered.map(async (f) => {
121
+ // Note: in the case where the function is removed, but the metadata
122
+ // is not updated, we ignore the Function not found error.
123
+ try {
124
+ const config = await lambda.send(new GetFunctionConfigurationCommand({
125
+ FunctionName: f.data.arn,
126
+ }));
127
+ await lambda.send(new UpdateFunctionConfigurationCommand({
128
+ FunctionName: f.data.arn,
129
+ Environment: {
130
+ Variables: {
131
+ ...(config.Environment?.Variables || {}),
132
+ [SECRET_UPDATED_AT_ENV]: Date.now().toString(),
133
+ },
130
134
  },
131
- },
132
- }));
135
+ }));
136
+ return true;
137
+ }
138
+ catch (e) {
139
+ if (e.name === "ResourceNotFoundException" &&
140
+ e.message.startsWith("Function not found")) {
141
+ return;
142
+ }
143
+ }
133
144
  }));
134
- return filtered.length;
145
+ return restarted.filter(Boolean).length;
135
146
  }
136
147
  Config.restart = restart;
137
148
  })(Config || (Config = {}));
@@ -352,13 +352,11 @@ export interface NodeJSProps {
352
352
  *
353
353
  * @example
354
354
  * ```js
355
- * new Function(stack, "Function", {
356
- * nodejs: {
357
- * loader: {
358
- * ".png": "file"
359
- * }
355
+ * nodejs: {
356
+ * loader: {
357
+ * ".png": "file"
360
358
  * }
361
- * })
359
+ * }
362
360
  * ```
363
361
  */
364
362
  loader?: Record<string, Loader>;
@@ -367,11 +365,9 @@ export interface NodeJSProps {
367
365
  *
368
366
  * @example
369
367
  * ```js
370
- * new Function(stack, "Function", {
371
- * nodejs: {
372
- * install: ["pg"]
373
- * }
374
- * })
368
+ * nodejs: {
369
+ * install: ["pg"]
370
+ * }
375
371
  * ```
376
372
  */
377
373
  install?: string[];
@@ -380,11 +376,9 @@ export interface NodeJSProps {
380
376
  *
381
377
  * @example
382
378
  * ```js
383
- * new Function(stack, "Function", {
384
- * nodejs: {
385
- * banner: "console.log('Function starting')"
386
- * }
387
- * })
379
+ * nodejs: {
380
+ * banner: "console.log('Function starting')"
381
+ * }
388
382
  * ```
389
383
  */
390
384
  banner?: string;
@@ -399,11 +393,9 @@ export interface NodeJSProps {
399
393
  *
400
394
  * @example
401
395
  * ```js
402
- * new Function(stack, "Function", {
403
- * nodejs: {
404
- * minify: false
405
- * }
406
- * })
396
+ * nodejs: {
397
+ * minify: false
398
+ * }
407
399
  * ```
408
400
  */
409
401
  minify?: boolean;
@@ -414,11 +406,9 @@ export interface NodeJSProps {
414
406
  *
415
407
  * @example
416
408
  * ```js
417
- * new Function(stack, "Function", {
418
- * nodejs: {
419
- * format: "esm"
420
- * }
421
- * })
409
+ * nodejs: {
410
+ * format: "esm"
411
+ * }
422
412
  * ```
423
413
  */
424
414
  format?: "cjs" | "esm";
@@ -429,11 +419,9 @@ export interface NodeJSProps {
429
419
  *
430
420
  * @example
431
421
  * ```js
432
- * new Function(stack, "Function", {
433
- * nodejs: {
434
- * sourcemap: true
435
- * }
436
- * })
422
+ * nodejs: {
423
+ * sourcemap: true
424
+ * }
437
425
  * ```
438
426
  */
439
427
  sourcemap?: boolean;
@@ -6,7 +6,8 @@ import { Permissions } from "./util/permission.js";
6
6
  import { FunctionBindingProps } from "./util/functionBinding.js";
7
7
  import { IVpc } from "aws-cdk-lib/aws-ec2";
8
8
  export type JobMemorySize = "3 GB" | "7 GB" | "15 GB" | "145 GB";
9
- export type JobNodeJSProps = NodeJSProps;
9
+ export interface JobNodeJSProps extends NodeJSProps {
10
+ }
10
11
  export interface JobProps {
11
12
  /**
12
13
  * Path to the entry point and handler function. Of the format:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.1.10",
3
+ "version": "2.1.12",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
@@ -186,13 +186,19 @@ export const useNodeHandler = Context.memo(async () => {
186
186
  }
187
187
  catch (ex) {
188
188
  const result = ex;
189
+ if ("errors" in result) {
190
+ return {
191
+ type: "error",
192
+ errors: result.errors.flatMap((x) => [
193
+ Colors.bold(x.text),
194
+ x.location?.file || "",
195
+ Colors.dim(x.location?.line, "│", x.location?.lineText),
196
+ ]),
197
+ };
198
+ }
189
199
  return {
190
200
  type: "error",
191
- errors: result.errors.flatMap((x) => [
192
- Colors.bold(x.text),
193
- x.location?.file || "",
194
- Colors.dim(x.location?.line, "│", x.location?.lineText),
195
- ]),
201
+ errors: [ex.toString()],
196
202
  };
197
203
  }
198
204
  },
package/sst.mjs CHANGED
@@ -3180,8 +3180,10 @@ async function monitor(stack) {
3180
3180
  "Resource creation cancelled"
3181
3181
  ) || event.ResourceStatusReason.includes(
3182
3182
  "Resource update cancelled"
3183
- ) || event.ResourceStatusReason?.includes(
3183
+ ) || event.ResourceStatusReason.includes(
3184
3184
  "Resource creation Initiated"
3185
+ ) || event.ResourceStatusReason.startsWith(
3186
+ "The following resource(s) failed to"
3185
3187
  ))
3186
3188
  continue;
3187
3189
  errors[event.LogicalResourceId] = event.ResourceStatusReason;
@@ -3200,7 +3202,11 @@ async function monitor(stack) {
3200
3202
  "Resource creation cancelled"
3201
3203
  ) || resource.ResourceStatusReason?.includes(
3202
3204
  "Resource update cancelled"
3203
- ) || resource.ResourceStatusReason?.includes("Resource creation Initiated"))
3205
+ ) || resource.ResourceStatusReason?.includes(
3206
+ "Resource creation Initiated"
3207
+ ) || resource.ResourceStatusReason?.startsWith(
3208
+ "The following resource(s) failed to"
3209
+ ))
3204
3210
  continue;
3205
3211
  if (resource.ResourceStatusReason)
3206
3212
  errors[resource.LogicalResourceId] = resource.ResourceStatusReason;
@@ -5056,13 +5062,19 @@ var init_node = __esm({
5056
5062
  };
5057
5063
  } catch (ex) {
5058
5064
  const result = ex;
5065
+ if ("errors" in result) {
5066
+ return {
5067
+ type: "error",
5068
+ errors: result.errors.flatMap((x) => [
5069
+ Colors.bold(x.text),
5070
+ x.location?.file || "",
5071
+ Colors.dim(x.location?.line, "\u2502", x.location?.lineText)
5072
+ ])
5073
+ };
5074
+ }
5059
5075
  return {
5060
5076
  type: "error",
5061
- errors: result.errors.flatMap((x) => [
5062
- Colors.bold(x.text),
5063
- x.location?.file || "",
5064
- Colors.dim(x.location?.line, "\u2502", x.location?.lineText)
5065
- ])
5077
+ errors: [ex.toString()]
5066
5078
  };
5067
5079
  }
5068
5080
  }
@@ -6566,27 +6578,34 @@ var init_config = __esm({
6566
6578
  const lambda = useAWSClient(LambdaClient);
6567
6579
  const metadata3 = await stacks_exports.metadata();
6568
6580
  const filtered = Object.values(metadata3).flat().filter((f) => f.type === "Function").filter((f) => f.data.secrets.includes(key));
6569
- await Promise.all(
6581
+ const restarted = await Promise.all(
6570
6582
  filtered.map(async (f) => {
6571
- const config = await lambda.send(
6572
- new GetFunctionConfigurationCommand({
6573
- FunctionName: f.data.arn
6574
- })
6575
- );
6576
- await lambda.send(
6577
- new UpdateFunctionConfigurationCommand({
6578
- FunctionName: f.data.arn,
6579
- Environment: {
6580
- Variables: {
6581
- ...config.Environment?.Variables || {},
6582
- [SECRET_UPDATED_AT_ENV]: Date.now().toString()
6583
+ try {
6584
+ const config = await lambda.send(
6585
+ new GetFunctionConfigurationCommand({
6586
+ FunctionName: f.data.arn
6587
+ })
6588
+ );
6589
+ await lambda.send(
6590
+ new UpdateFunctionConfigurationCommand({
6591
+ FunctionName: f.data.arn,
6592
+ Environment: {
6593
+ Variables: {
6594
+ ...config.Environment?.Variables || {},
6595
+ [SECRET_UPDATED_AT_ENV]: Date.now().toString()
6596
+ }
6583
6597
  }
6584
- }
6585
- })
6586
- );
6598
+ })
6599
+ );
6600
+ return true;
6601
+ } catch (e) {
6602
+ if (e.name === "ResourceNotFoundException" && e.message.startsWith("Function not found")) {
6603
+ return;
6604
+ }
6605
+ }
6587
6606
  })
6588
6607
  );
6589
- return filtered.length;
6608
+ return restarted.filter(Boolean).length;
6590
6609
  }
6591
6610
  Config2.restart = restart;
6592
6611
  })(Config || (Config = {}));
package/stacks/monitor.js CHANGED
@@ -81,7 +81,9 @@ export async function monitor(stack) {
81
81
  if (event.ResourceStatusReason) {
82
82
  if (event.ResourceStatusReason.includes("Resource creation cancelled") ||
83
83
  event.ResourceStatusReason.includes("Resource update cancelled") ||
84
- event.ResourceStatusReason?.includes("Resource creation Initiated"))
84
+ event.ResourceStatusReason.includes("Resource creation Initiated") ||
85
+ // ie. The following resource(s) failed to update: [MyResource10A5921D].
86
+ event.ResourceStatusReason.startsWith("The following resource(s) failed to"))
85
87
  continue;
86
88
  errors[event.LogicalResourceId] = event.ResourceStatusReason;
87
89
  }
@@ -97,7 +99,9 @@ export async function monitor(stack) {
97
99
  for (const resource of resources.StackResources || []) {
98
100
  if (resource.ResourceStatusReason?.includes("Resource creation cancelled") ||
99
101
  resource.ResourceStatusReason?.includes("Resource update cancelled") ||
100
- resource.ResourceStatusReason?.includes("Resource creation Initiated"))
102
+ resource.ResourceStatusReason?.includes("Resource creation Initiated") ||
103
+ // ie. The following resource(s) failed to update: [MyResource10A5921D].
104
+ resource.ResourceStatusReason?.startsWith("The following resource(s) failed to"))
101
105
  continue;
102
106
  if (resource.ResourceStatusReason)
103
107
  errors[resource.LogicalResourceId] = resource.ResourceStatusReason;
@@ -32746,14 +32746,11 @@ function safeHandler(block) {
32746
32746
  );
32747
32747
  }
32748
32748
  }
32749
- const reason = [
32750
- e.message,
32751
- `Logs: https://${process.env.AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${process.env.AWS_REGION}#logsV2:log-groups/log-group/${encodeURIComponent(
32752
- process.env.AWS_LAMBDA_LOG_GROUP_NAME
32753
- )}/log-events/${encodeURIComponent(
32754
- process.env.AWS_LAMBDA_LOG_STREAM_NAME
32755
- )}`
32756
- ].join("\n");
32749
+ const reason = e.reason || `${e.message} - Logs: https://${process.env.AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${process.env.AWS_REGION}#logsV2:log-groups/log-group/${encodeURIComponent(
32750
+ process.env.AWS_LAMBDA_LOG_GROUP_NAME
32751
+ )}/log-events/${encodeURIComponent(
32752
+ process.env.AWS_LAMBDA_LOG_STREAM_NAME
32753
+ )}`;
32757
32754
  await submitResponse("FAILED", event, { reason });
32758
32755
  }
32759
32756
  };
@@ -32838,6 +32835,14 @@ async function invokeUserFunction(functionName, payload) {
32838
32835
  Payload: Buffer.from(JSON.stringify(payload))
32839
32836
  })
32840
32837
  );
32838
+ if (resp.FunctionError) {
32839
+ const payload2 = JSON.parse(Buffer.from(resp.Payload).toString());
32840
+ const error = new Error();
32841
+ error.reason = `${payload2.errorType}: ${payload2.errorMessage} - https://${process.env.AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${process.env.AWS_REGION}#logsV2:log-groups/log-group/${encodeURIComponent(
32842
+ `/aws/lambda/${functionName}`
32843
+ )}`;
32844
+ throw error;
32845
+ }
32841
32846
  log(`response`, resp);
32842
32847
  }
32843
32848
  __name(invokeUserFunction, "invokeUserFunction");