sst 2.0.23 → 2.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
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
  });
@@ -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({
@@ -4971,7 +4975,7 @@ var init_go = __esm({
4971
4975
  const handlers = useRuntimeHandlers();
4972
4976
  const processes = /* @__PURE__ */ new Map();
4973
4977
  const sources = /* @__PURE__ */ new Map();
4974
- const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
4978
+ const handlerName = process.platform === "win32" ? `bootstrap.exe` : `bootstrap`;
4975
4979
  handlers.register({
4976
4980
  shouldBuild: (input) => {
4977
4981
  const parent = sources.get(input.functionID);
@@ -5029,26 +5033,23 @@ var init_go = __esm({
5029
5033
  }
5030
5034
  if (input.mode === "deploy") {
5031
5035
  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
- }
5036
+ const target = path11.join(input.out, "bootstrap");
5037
+ await execAsync2(`go build -ldflags '-s -w' -o ${target} ./${src}`, {
5038
+ cwd: project,
5039
+ env: {
5040
+ ...process.env,
5041
+ CGO_ENABLED: "0",
5042
+ GOARCH: input.props.architecture === "arm_64" ? "arm64" : "amd64",
5043
+ GOOS: "linux"
5043
5044
  }
5044
- );
5045
+ });
5045
5046
  } catch {
5046
5047
  throw new VisibleError("Failed to build");
5047
5048
  }
5048
5049
  }
5049
5050
  return {
5050
5051
  type: "success",
5051
- handler: "handler"
5052
+ handler: "bootstrap"
5052
5053
  };
5053
5054
  }
5054
5055
  });
@@ -5203,6 +5204,14 @@ var init_python = __esm({
5203
5204
  const handlers = useRuntimeHandlers();
5204
5205
  const processes = /* @__PURE__ */ new Map();
5205
5206
  const sources = /* @__PURE__ */ new Map();
5207
+ async function findSrc(input) {
5208
+ const hints = ["requirements.txt", "Pipfile", "poetry.lock"];
5209
+ for (const hint of hints) {
5210
+ const result = await findAbove(input, hint);
5211
+ if (result)
5212
+ return result;
5213
+ }
5214
+ }
5206
5215
  handlers.register({
5207
5216
  shouldBuild: (input) => {
5208
5217
  const parent = sources.get(input.functionID);
@@ -5212,7 +5221,9 @@ var init_python = __esm({
5212
5221
  },
5213
5222
  canHandle: (input) => input.startsWith("python"),
5214
5223
  startWorker: async (input) => {
5215
- const src = await findAbove(input.handler, "requirements.txt");
5224
+ const src = await findSrc(input.handler);
5225
+ if (!src)
5226
+ throw new Error(`Could not find src for ${input.handler}`);
5216
5227
  const parsed = path13.parse(path13.relative(src, input.handler));
5217
5228
  const target = [...parsed.dir.split(path13.sep), parsed.name].join(".");
5218
5229
  const proc = spawn5(
@@ -5260,7 +5271,23 @@ var init_python = __esm({
5260
5271
  type: "success",
5261
5272
  handler: input.props.handler
5262
5273
  };
5263
- const src = await findAbove(input.props.handler, "requirements.txt");
5274
+ const src = await findSrc(input.props.handler);
5275
+ if (!src)
5276
+ return {
5277
+ type: "error",
5278
+ errors: [`Could not find src for ${input.props.handler}`]
5279
+ };
5280
+ if (await existsAsync(path13.join(src, "Pipfile"))) {
5281
+ await execAsync4("pipenv requirements > requirements.txt");
5282
+ }
5283
+ if (await existsAsync(path13.join(src, "poetry.lock"))) {
5284
+ await execAsync4(
5285
+ "poetry export --with-credentials --format requirements.txt --output requirements.txt"
5286
+ );
5287
+ }
5288
+ if (await existsAsync(path13.join(src, "requirements.txt"))) {
5289
+ await execAsync4("pip install -r requirements.txt");
5290
+ }
5264
5291
  await fs13.cp(src, input.out, {
5265
5292
  recursive: true,
5266
5293
  filter: (src2) => !src2.includes(".sst")
@@ -6566,7 +6593,7 @@ var dev = (program2) => program2.command(
6566
6593
  prefix(evt.properties.requestID),
6567
6594
  Colors2.dim.bold("Invoked"),
6568
6595
  Colors2.dim(
6569
- useFunctions3().fromID(evt.properties.functionID).handler
6596
+ useFunctions3().fromID(evt.properties.functionID)?.handler
6570
6597
  )
6571
6598
  );
6572
6599
  });