sst 2.0.23 → 2.0.25

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,7 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
57
57
  pending.delete(requestID);
58
58
  }
59
59
  bus.subscribe("function.invoked", async (evt) => {
60
- Colors.line(prefix(evt.properties.requestID), Colors.dim.bold("Invoked"), Colors.dim(useFunctions().fromID(evt.properties.functionID).handler));
60
+ Colors.line(prefix(evt.properties.requestID), Colors.dim.bold("Invoked"), Colors.dim(useFunctions().fromID(evt.properties.functionID)?.handler));
61
61
  });
62
62
  bus.subscribe("worker.stdout", async (evt) => {
63
63
  prefix(evt.properties.requestID);
@@ -1,18 +1,23 @@
1
1
  import https from "https";
2
2
  export function postPayload(endpoint, body) {
3
3
  return new Promise((resolve, reject) => {
4
- const req = https.request(endpoint, {
5
- method: "POST",
6
- headers: { "content-type": "application/json" },
7
- timeout: 5000,
8
- }, (resp) => {
9
- if (resp.statusCode !== 200) {
10
- reject(new Error(`Unexpected status code: ${resp.statusCode}`));
11
- return;
12
- }
4
+ try {
5
+ const req = https.request(endpoint, {
6
+ method: "POST",
7
+ headers: { "content-type": "application/json" },
8
+ timeout: 5000,
9
+ }, (resp) => {
10
+ if (resp.statusCode !== 200) {
11
+ reject(new Error(`Unexpected status code: ${resp.statusCode}`));
12
+ return;
13
+ }
14
+ resolve();
15
+ });
16
+ req.write(JSON.stringify(body));
17
+ req.end();
18
+ }
19
+ catch {
13
20
  resolve();
14
- });
15
- req.write(JSON.stringify(body));
16
- req.end();
21
+ }
17
22
  });
18
23
  }
@@ -33,6 +33,7 @@ declare const supportedRuntimes: {
33
33
  java8: cdk.aws_lambda.Runtime;
34
34
  java11: cdk.aws_lambda.Runtime;
35
35
  "go1.x": cdk.aws_lambda.Runtime;
36
+ go: cdk.aws_lambda.Runtime;
36
37
  };
37
38
  export type Runtime = keyof typeof supportedRuntimes;
38
39
  export type FunctionInlineDefinition = string | Function;
@@ -19,6 +19,7 @@ import { useDeferredTasks } from "./deferred_task.js";
19
19
  import { useProject } from "../project.js";
20
20
  import { useRuntimeHandlers } from "../runtime/handlers.js";
21
21
  import { createAppContext } from "./context.js";
22
+ import { useWarning } from "./util/warning.js";
22
23
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
23
24
  const supportedRuntimes = {
24
25
  rust: lambda.Runtime.PROVIDED_AL2,
@@ -43,7 +44,8 @@ const supportedRuntimes = {
43
44
  dotnet6: lambda.Runtime.DOTNET_6,
44
45
  java8: lambda.Runtime.JAVA_8,
45
46
  java11: lambda.Runtime.JAVA_11,
46
- "go1.x": lambda.Runtime.GO_1_X,
47
+ "go1.x": lambda.Runtime.PROVIDED_AL2,
48
+ go: lambda.Runtime.PROVIDED_AL2,
47
49
  };
48
50
  /**
49
51
  * The `Function` construct is a higher level CDK construct that makes it easy to create a Lambda Function with support for Live Lambda Development.
@@ -77,6 +79,8 @@ export class Function extends lambda.Function {
77
79
  props = Function.mergeProps(per, props);
78
80
  });
79
81
  props.runtime = props.runtime || "nodejs16.x";
82
+ if (props.runtime === "go1.x")
83
+ useWarning().add("go.deprecated");
80
84
  // Set defaults
81
85
  const functionName = props.functionName &&
82
86
  (typeof props.functionName === "string"
@@ -1,6 +1,7 @@
1
1
  declare const WARNINGS: {
2
2
  "config.deprecated": string;
3
3
  "permissions.noConstructs": string;
4
+ "go.deprecated": string;
4
5
  };
5
6
  export declare const useWarning: () => {
6
7
  add(message: keyof typeof WARNINGS): void;
@@ -2,6 +2,7 @@ import { createAppContext } from "../context.js";
2
2
  const WARNINGS = {
3
3
  "config.deprecated": `WARNING: The "config" prop is deprecated, and will be removed in SST v2. Pass Parameters and Secrets in through the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/upgrade-guide#upgrade-to-v116`,
4
4
  "permissions.noConstructs": `WARNING: Passing SST constructs into "permissions" is deprecated, and will be removed in SST v2. Pass them into the "bind" prop. Read more about how to upgrade here — https://docs.serverless-stack.com/upgrade-guide#upgrade-to-v116`,
5
+ "go.deprecated": `WARNING: The "go1.x" runtime is deprecated and replaced by the "go" runtime`,
5
6
  };
6
7
  export const useWarning = createAppContext(() => {
7
8
  const set = new Set();
package/credentials.js CHANGED
@@ -24,8 +24,10 @@ export const useAWSCredentialsProvider = Context.memo(() => {
24
24
  resolve(input.trim());
25
25
  rl.close();
26
26
  }
27
- // prompt again if no input
28
- prompt();
27
+ else {
28
+ // prompt again if no input
29
+ prompt();
30
+ }
29
31
  });
30
32
  prompt();
31
33
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.23",
3
+ "version": "2.0.25",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
@@ -15,7 +15,7 @@ export const useGoHandler = Context.memo(async () => {
15
15
  const handlers = useRuntimeHandlers();
16
16
  const processes = new Map();
17
17
  const sources = new Map();
18
- const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
18
+ const handlerName = process.platform === "win32" ? `bootstrap.exe` : `bootstrap`;
19
19
  handlers.register({
20
20
  shouldBuild: (input) => {
21
21
  const parent = sources.get(input.functionID);
@@ -71,13 +71,13 @@ export const useGoHandler = Context.memo(async () => {
71
71
  }
72
72
  if (input.mode === "deploy") {
73
73
  try {
74
- const target = path.join(input.out, "handler");
75
- const result = await execAsync(`go build -ldflags '-s -w' -o ${target} ./${src}`, {
74
+ const target = path.join(input.out, "bootstrap");
75
+ await execAsync(`go build -ldflags '-s -w' -o ${target} ./${src}`, {
76
76
  cwd: project,
77
77
  env: {
78
78
  ...process.env,
79
79
  CGO_ENABLED: "0",
80
- GOARCH: "amd64",
80
+ GOARCH: input.props.architecture === "arm_64" ? "arm64" : "amd64",
81
81
  GOOS: "linux",
82
82
  },
83
83
  });
@@ -88,7 +88,7 @@ export const useGoHandler = Context.memo(async () => {
88
88
  }
89
89
  return {
90
90
  type: "success",
91
- handler: "handler",
91
+ handler: "bootstrap",
92
92
  };
93
93
  },
94
94
  });
@@ -104,6 +104,7 @@ export const useNodeHandler = Context.memo(async () => {
104
104
  ...(nodejs.install || []),
105
105
  ...(external || []),
106
106
  ],
107
+ loader: nodejs.loader,
107
108
  keepNames: true,
108
109
  bundle: true,
109
110
  logLevel: "silent",
@@ -5,7 +5,7 @@ import { Context } from "../../context/context.js";
5
5
  import { exec, spawn } from "child_process";
6
6
  import { promisify } from "util";
7
7
  import { useRuntimeServerConfig } from "../server.js";
8
- import { findAbove, isChild } from "../../util/fs.js";
8
+ import { existsAsync, findAbove, isChild } from "../../util/fs.js";
9
9
  import { Runtime } from "aws-cdk-lib/aws-lambda";
10
10
  import fs from "fs/promises";
11
11
  const execAsync = promisify(exec);
@@ -24,6 +24,14 @@ export const usePythonHandler = Context.memo(async () => {
24
24
  const handlers = useRuntimeHandlers();
25
25
  const processes = new Map();
26
26
  const sources = new Map();
27
+ async function findSrc(input) {
28
+ const hints = ["requirements.txt", "Pipfile", "poetry.lock"];
29
+ for (const hint of hints) {
30
+ const result = await findAbove(input, hint);
31
+ if (result)
32
+ return result;
33
+ }
34
+ }
27
35
  handlers.register({
28
36
  shouldBuild: (input) => {
29
37
  const parent = sources.get(input.functionID);
@@ -33,7 +41,9 @@ export const usePythonHandler = Context.memo(async () => {
33
41
  },
34
42
  canHandle: (input) => input.startsWith("python"),
35
43
  startWorker: async (input) => {
36
- const src = await findAbove(input.handler, "requirements.txt");
44
+ const src = await findSrc(input.handler);
45
+ if (!src)
46
+ throw new Error(`Could not find src for ${input.handler}`);
37
47
  const parsed = path.parse(path.relative(src, input.handler));
38
48
  const target = [...parsed.dir.split(path.sep), parsed.name].join(".");
39
49
  const proc = spawn(os.platform() === "win32" ? "python.exe" : "python3", [
@@ -75,7 +85,21 @@ export const usePythonHandler = Context.memo(async () => {
75
85
  type: "success",
76
86
  handler: input.props.handler,
77
87
  };
78
- const src = await findAbove(input.props.handler, "requirements.txt");
88
+ const src = await findSrc(input.props.handler);
89
+ if (!src)
90
+ return {
91
+ type: "error",
92
+ errors: [`Could not find src for ${input.props.handler}`],
93
+ };
94
+ if (await existsAsync(path.join(src, "Pipfile"))) {
95
+ await execAsync("pipenv requirements > requirements.txt");
96
+ }
97
+ if (await existsAsync(path.join(src, "poetry.lock"))) {
98
+ await execAsync("poetry export --with-credentials --format requirements.txt --output requirements.txt");
99
+ }
100
+ if (await existsAsync(path.join(src, "requirements.txt"))) {
101
+ await execAsync("pip install -r requirements.txt");
102
+ }
79
103
  await fs.cp(src, input.out, {
80
104
  recursive: true,
81
105
  filter: (src) => !src.includes(".sst"),
package/sst.mjs CHANGED
@@ -455,23 +455,27 @@ var init_project = __esm({
455
455
  import https from "https";
456
456
  function postPayload(endpoint, body) {
457
457
  return new Promise((resolve, reject) => {
458
- const req = https.request(
459
- endpoint,
460
- {
461
- method: "POST",
462
- headers: { "content-type": "application/json" },
463
- timeout: 5e3
464
- },
465
- (resp) => {
466
- if (resp.statusCode !== 200) {
467
- reject(new Error(`Unexpected status code: ${resp.statusCode}`));
468
- return;
458
+ try {
459
+ const req = https.request(
460
+ endpoint,
461
+ {
462
+ method: "POST",
463
+ headers: { "content-type": "application/json" },
464
+ timeout: 5e3
465
+ },
466
+ (resp) => {
467
+ if (resp.statusCode !== 200) {
468
+ reject(new Error(`Unexpected status code: ${resp.statusCode}`));
469
+ return;
470
+ }
471
+ resolve();
469
472
  }
470
- resolve();
471
- }
472
- );
473
- req.write(JSON.stringify(body));
474
- req.end();
473
+ );
474
+ req.write(JSON.stringify(body));
475
+ req.end();
476
+ } catch {
477
+ resolve();
478
+ }
475
479
  });
476
480
  }
477
481
  var init_post_payload = __esm({
@@ -1550,8 +1554,9 @@ var init_credentials = __esm({
1550
1554
  if (input.trim() !== "") {
1551
1555
  resolve(input.trim());
1552
1556
  rl.close();
1557
+ } else {
1558
+ prompt();
1553
1559
  }
1554
- prompt();
1555
1560
  });
1556
1561
  prompt();
1557
1562
  });
@@ -4844,6 +4849,7 @@ var init_node = __esm({
4844
4849
  ...nodejs.install || [],
4845
4850
  ...external || []
4846
4851
  ],
4852
+ loader: nodejs.loader,
4847
4853
  keepNames: true,
4848
4854
  bundle: true,
4849
4855
  logLevel: "silent",
@@ -4971,7 +4977,7 @@ var init_go = __esm({
4971
4977
  const handlers = useRuntimeHandlers();
4972
4978
  const processes = /* @__PURE__ */ new Map();
4973
4979
  const sources = /* @__PURE__ */ new Map();
4974
- const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
4980
+ const handlerName = process.platform === "win32" ? `bootstrap.exe` : `bootstrap`;
4975
4981
  handlers.register({
4976
4982
  shouldBuild: (input) => {
4977
4983
  const parent = sources.get(input.functionID);
@@ -5029,26 +5035,23 @@ var init_go = __esm({
5029
5035
  }
5030
5036
  if (input.mode === "deploy") {
5031
5037
  try {
5032
- const target = path11.join(input.out, "handler");
5033
- const result = await execAsync2(
5034
- `go build -ldflags '-s -w' -o ${target} ./${src}`,
5035
- {
5036
- cwd: project,
5037
- env: {
5038
- ...process.env,
5039
- CGO_ENABLED: "0",
5040
- GOARCH: "amd64",
5041
- GOOS: "linux"
5042
- }
5038
+ const target = path11.join(input.out, "bootstrap");
5039
+ await execAsync2(`go build -ldflags '-s -w' -o ${target} ./${src}`, {
5040
+ cwd: project,
5041
+ env: {
5042
+ ...process.env,
5043
+ CGO_ENABLED: "0",
5044
+ GOARCH: input.props.architecture === "arm_64" ? "arm64" : "amd64",
5045
+ GOOS: "linux"
5043
5046
  }
5044
- );
5047
+ });
5045
5048
  } catch {
5046
5049
  throw new VisibleError("Failed to build");
5047
5050
  }
5048
5051
  }
5049
5052
  return {
5050
5053
  type: "success",
5051
- handler: "handler"
5054
+ handler: "bootstrap"
5052
5055
  };
5053
5056
  }
5054
5057
  });
@@ -5203,6 +5206,14 @@ var init_python = __esm({
5203
5206
  const handlers = useRuntimeHandlers();
5204
5207
  const processes = /* @__PURE__ */ new Map();
5205
5208
  const sources = /* @__PURE__ */ new Map();
5209
+ async function findSrc(input) {
5210
+ const hints = ["requirements.txt", "Pipfile", "poetry.lock"];
5211
+ for (const hint of hints) {
5212
+ const result = await findAbove(input, hint);
5213
+ if (result)
5214
+ return result;
5215
+ }
5216
+ }
5206
5217
  handlers.register({
5207
5218
  shouldBuild: (input) => {
5208
5219
  const parent = sources.get(input.functionID);
@@ -5212,7 +5223,9 @@ var init_python = __esm({
5212
5223
  },
5213
5224
  canHandle: (input) => input.startsWith("python"),
5214
5225
  startWorker: async (input) => {
5215
- const src = await findAbove(input.handler, "requirements.txt");
5226
+ const src = await findSrc(input.handler);
5227
+ if (!src)
5228
+ throw new Error(`Could not find src for ${input.handler}`);
5216
5229
  const parsed = path13.parse(path13.relative(src, input.handler));
5217
5230
  const target = [...parsed.dir.split(path13.sep), parsed.name].join(".");
5218
5231
  const proc = spawn5(
@@ -5260,7 +5273,23 @@ var init_python = __esm({
5260
5273
  type: "success",
5261
5274
  handler: input.props.handler
5262
5275
  };
5263
- const src = await findAbove(input.props.handler, "requirements.txt");
5276
+ const src = await findSrc(input.props.handler);
5277
+ if (!src)
5278
+ return {
5279
+ type: "error",
5280
+ errors: [`Could not find src for ${input.props.handler}`]
5281
+ };
5282
+ if (await existsAsync(path13.join(src, "Pipfile"))) {
5283
+ await execAsync4("pipenv requirements > requirements.txt");
5284
+ }
5285
+ if (await existsAsync(path13.join(src, "poetry.lock"))) {
5286
+ await execAsync4(
5287
+ "poetry export --with-credentials --format requirements.txt --output requirements.txt"
5288
+ );
5289
+ }
5290
+ if (await existsAsync(path13.join(src, "requirements.txt"))) {
5291
+ await execAsync4("pip install -r requirements.txt");
5292
+ }
5264
5293
  await fs13.cp(src, input.out, {
5265
5294
  recursive: true,
5266
5295
  filter: (src2) => !src2.includes(".sst")
@@ -6566,7 +6595,7 @@ var dev = (program2) => program2.command(
6566
6595
  prefix(evt.properties.requestID),
6567
6596
  Colors2.dim.bold("Invoked"),
6568
6597
  Colors2.dim(
6569
- useFunctions3().fromID(evt.properties.functionID).handler
6598
+ useFunctions3().fromID(evt.properties.functionID)?.handler
6570
6599
  )
6571
6600
  );
6572
6601
  });