sst 2.0.0-rc.8 → 2.0.0

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.
Files changed (243) hide show
  1. package/bootstrap.d.ts +2 -4
  2. package/bootstrap.js +208 -61
  3. package/bus.d.ts +3 -3
  4. package/bus.js +1 -1
  5. package/cache.js +1 -1
  6. package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
  7. package/cdk/cloudformation-deployments-wrapper.js +117 -0
  8. package/cdk/cloudformation-deployments.d.ts +19 -4
  9. package/cdk/deploy-stack.d.ts +17 -2
  10. package/cdk/deploy-stack.js +6 -1
  11. package/cli/colors.d.ts +28 -0
  12. package/cli/colors.js +27 -0
  13. package/cli/commands/bind.d.ts +4 -0
  14. package/cli/commands/bind.js +10 -7
  15. package/cli/commands/bootstrap.d.ts +13 -0
  16. package/cli/commands/bootstrap.js +11 -0
  17. package/cli/commands/build.d.ts +6 -2
  18. package/cli/commands/build.js +13 -8
  19. package/cli/commands/console.d.ts +5 -1
  20. package/cli/commands/console.js +8 -6
  21. package/cli/commands/deploy.d.ts +4 -2
  22. package/cli/commands/deploy.js +71 -29
  23. package/cli/commands/dev.d.ts +5 -1
  24. package/cli/commands/dev.js +157 -79
  25. package/cli/commands/diff.d.ts +15 -0
  26. package/cli/commands/diff.js +61 -0
  27. package/cli/commands/env.d.ts +5 -1
  28. package/cli/commands/env.js +14 -15
  29. package/cli/commands/plugins/kysely.js +13 -5
  30. package/cli/commands/plugins/pothos.js +9 -4
  31. package/cli/commands/remove.d.ts +4 -0
  32. package/cli/commands/remove.js +26 -18
  33. package/cli/commands/secrets/get.d.ts +7 -3
  34. package/cli/commands/secrets/get.js +11 -24
  35. package/cli/commands/secrets/list.d.ts +6 -2
  36. package/cli/commands/secrets/list.js +15 -7
  37. package/cli/commands/secrets/remove.d.ts +8 -4
  38. package/cli/commands/secrets/remove.js +18 -16
  39. package/cli/commands/secrets/secrets.js +3 -3
  40. package/cli/commands/secrets/set.d.ts +8 -6
  41. package/cli/commands/secrets/set.js +16 -33
  42. package/cli/commands/telemetry.d.ts +15 -0
  43. package/cli/commands/telemetry.js +17 -0
  44. package/cli/commands/transform.d.ts +15 -0
  45. package/cli/commands/transform.js +55 -0
  46. package/cli/commands/update.d.ts +6 -2
  47. package/cli/commands/update.js +41 -33
  48. package/cli/commands/version.d.ts +13 -0
  49. package/cli/commands/version.js +7 -0
  50. package/cli/local/router.d.ts +6 -6
  51. package/cli/local/router.js +3 -3
  52. package/cli/local/server.d.ts +5 -3
  53. package/cli/local/server.js +21 -14
  54. package/cli/program.d.ts +5 -1
  55. package/cli/program.js +29 -5
  56. package/cli/spinner.js +2 -0
  57. package/cli/sst.js +35 -23
  58. package/cli/telemetry/environment.d.ts +1 -1
  59. package/cli/telemetry/environment.js +1 -1
  60. package/cli/terminal.d.ts +1 -0
  61. package/cli/terminal.js +8 -0
  62. package/cli/ui/deploy.d.ts +3 -2
  63. package/cli/ui/deploy.js +106 -106
  64. package/cli/ui/functions.d.ts +2 -0
  65. package/cli/ui/functions.js +132 -0
  66. package/cli/ui/header.d.ts +5 -0
  67. package/cli/ui/header.js +16 -0
  68. package/cli/ui/stack.d.ts +1 -0
  69. package/cli/ui/stack.js +6 -0
  70. package/config.d.ts +1 -1
  71. package/config.js +8 -8
  72. package/constructs/Api.d.ts +3 -71
  73. package/constructs/Api.js +3 -42
  74. package/constructs/ApiGatewayV1Api.d.ts +3 -3
  75. package/constructs/ApiGatewayV1Api.js +4 -3
  76. package/constructs/App.d.ts +2 -22
  77. package/constructs/App.js +12 -25
  78. package/constructs/AppSyncApi.d.ts +4 -5
  79. package/constructs/AppSyncApi.js +8 -5
  80. package/constructs/AstroSite.d.ts +2 -3
  81. package/constructs/AstroSite.js +43 -53
  82. package/constructs/Auth.js +27 -16
  83. package/constructs/BaseSite.d.ts +10 -10
  84. package/constructs/BaseSite.js +2 -2
  85. package/constructs/Cognito.js +28 -28
  86. package/constructs/EdgeFunction.d.ts +6 -4
  87. package/constructs/EdgeFunction.js +56 -59
  88. package/constructs/EventBus.js +1 -1
  89. package/constructs/Function.d.ts +4 -44
  90. package/constructs/Function.js +14 -50
  91. package/constructs/FunctionalStack.d.ts +2 -2
  92. package/constructs/Job.d.ts +23 -63
  93. package/constructs/Job.js +11 -32
  94. package/constructs/Metadata.d.ts +18 -20
  95. package/constructs/NextjsSite.d.ts +21 -5
  96. package/constructs/NextjsSite.js +67 -101
  97. package/constructs/Queue.js +10 -10
  98. package/constructs/RDS.d.ts +1 -1
  99. package/constructs/RDS.js +1 -1
  100. package/constructs/RemixSite.d.ts +0 -2
  101. package/constructs/RemixSite.js +20 -20
  102. package/constructs/Script.js +1 -1
  103. package/constructs/Secret.js +5 -3
  104. package/constructs/SolidStartSite.d.ts +2 -3
  105. package/constructs/SolidStartSite.js +42 -52
  106. package/constructs/SsrFunction.d.ts +22 -0
  107. package/constructs/SsrFunction.js +113 -0
  108. package/constructs/SsrSite.d.ts +104 -104
  109. package/constructs/SsrSite.js +196 -217
  110. package/constructs/Stack.d.ts +1 -20
  111. package/constructs/Stack.js +3 -65
  112. package/constructs/StaticSite.d.ts +33 -53
  113. package/constructs/StaticSite.js +92 -118
  114. package/constructs/Table.d.ts +1 -1
  115. package/constructs/Table.js +4 -4
  116. package/constructs/Topic.js +1 -1
  117. package/constructs/cdk/certificate-base.d.ts +18 -0
  118. package/constructs/cdk/certificate-base.js +26 -0
  119. package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
  120. package/constructs/cdk/dns-validated-certificate.js +125 -0
  121. package/constructs/cdk/website-redirect.d.ts +53 -0
  122. package/constructs/cdk/website-redirect.js +77 -0
  123. package/constructs/deferred_task.d.ts +1 -1
  124. package/constructs/deprecated/NextjsSite.js +8 -6
  125. package/constructs/index.d.ts +0 -6
  126. package/constructs/index.js +0 -6
  127. package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
  128. package/constructs/util/apiGatewayV2AccessLog.js +4 -4
  129. package/constructs/util/apiGatewayV2Domain.js +9 -2
  130. package/constructs/util/appSyncApiDomain.d.ts +1 -1
  131. package/constructs/util/appSyncApiDomain.js +9 -15
  132. package/constructs/util/duration.d.ts +1 -1
  133. package/constructs/util/functionBinding.js +1 -1
  134. package/constructs/util/permission.d.ts +3 -3
  135. package/constructs/util/permission.js +16 -18
  136. package/constructs/util/size.d.ts +1 -1
  137. package/constructs/util/warning.js +2 -2
  138. package/context/context.d.ts +2 -2
  139. package/context/context.js +4 -4
  140. package/context/handler.d.ts +1 -1
  141. package/credentials.d.ts +1 -1
  142. package/credentials.js +42 -6
  143. package/index.d.ts +1 -0
  144. package/index.js +1 -0
  145. package/iot.js +6 -2
  146. package/logger.js +3 -1
  147. package/node/api/index.d.ts +4 -3
  148. package/node/api/index.js +8 -2
  149. package/node/auth/adapter/adapter.d.ts +1 -1
  150. package/node/auth/adapter/facebook.js +1 -1
  151. package/node/auth/adapter/github.js +4 -4
  152. package/node/auth/adapter/google.d.ts +1 -1
  153. package/node/auth/adapter/google.js +2 -2
  154. package/node/auth/adapter/twitch.js +1 -1
  155. package/node/auth/session.d.ts +1 -1
  156. package/node/config/index.d.ts +2 -2
  157. package/node/config/index.js +3 -8
  158. package/node/job/index.d.ts +2 -2
  159. package/node/site/index.js +3 -5
  160. package/package.json +26 -21
  161. package/pothos.js +1 -0
  162. package/project.d.ts +47 -0
  163. package/{app.js → project.js} +60 -53
  164. package/runtime/handlers/dotnet.d.ts +1 -1
  165. package/runtime/handlers/dotnet.js +4 -4
  166. package/runtime/handlers/go.d.ts +1 -1
  167. package/runtime/handlers/go.js +3 -3
  168. package/runtime/handlers/java.d.ts +1 -1
  169. package/runtime/handlers/java.js +4 -4
  170. package/runtime/handlers/node.d.ts +1 -1
  171. package/runtime/handlers/node.js +60 -39
  172. package/runtime/handlers/python.d.ts +1 -1
  173. package/runtime/handlers/python.js +3 -3
  174. package/runtime/handlers.js +15 -12
  175. package/runtime/iot.js +3 -0
  176. package/runtime/runtime.d.ts +4 -0
  177. package/runtime/server.d.ts +3 -3
  178. package/runtime/server.js +11 -5
  179. package/runtime/workers.d.ts +4 -2
  180. package/runtime/workers.js +13 -3
  181. package/site-env.js +2 -1
  182. package/sst.mjs +6357 -20846
  183. package/stacks/app-metadata.d.ts +7 -0
  184. package/stacks/app-metadata.js +78 -0
  185. package/stacks/assembly.d.ts +1 -0
  186. package/stacks/assembly.js +4 -0
  187. package/stacks/build.d.ts +1 -1
  188. package/stacks/build.js +41 -48
  189. package/stacks/deploy.d.ts +1 -0
  190. package/stacks/deploy.js +128 -7
  191. package/stacks/diff.d.ts +8 -0
  192. package/stacks/diff.js +62 -0
  193. package/stacks/index.d.ts +3 -0
  194. package/stacks/index.js +3 -0
  195. package/stacks/metadata.d.ts +2 -0
  196. package/stacks/metadata.js +14 -12
  197. package/stacks/monitor.d.ts +8 -3
  198. package/stacks/monitor.js +38 -4
  199. package/stacks/remove.js +0 -4
  200. package/stacks/synth.d.ts +1 -0
  201. package/stacks/synth.js +27 -13
  202. package/support/base-site-archiver.mjs +1 -1
  203. package/support/bootstrap-metadata-function/index.mjs +68740 -0
  204. package/support/bridge/bridge.mjs +28 -28
  205. package/support/certificate-requestor/index.js +549 -0
  206. package/support/custom-resources/index.mjs +3824 -26567
  207. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
  208. package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
  209. package/support/edge-function/edge-lambda.mjs +2 -2
  210. package/support/job-invoker/index.mjs +26 -0
  211. package/support/nodejs-runtime/index.mjs +75 -72
  212. package/support/rds-migrator/index.mjs +22 -23
  213. package/support/remix-site-function/edge-server.js +1 -1
  214. package/support/script-function/index.mjs +30485 -0
  215. package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
  216. package/support/ssr-site-function-archiver.mjs +96 -0
  217. package/util/process.d.ts +0 -1
  218. package/watcher.js +1 -1
  219. package/app.d.ts +0 -36
  220. package/constructs/DebugApp.d.ts +0 -49
  221. package/constructs/DebugApp.js +0 -63
  222. package/constructs/DebugStack.d.ts +0 -34
  223. package/constructs/DebugStack.js +0 -132
  224. package/constructs/GraphQLApi.d.ts +0 -98
  225. package/constructs/GraphQLApi.js +0 -80
  226. package/constructs/ReactStaticSite.d.ts +0 -20
  227. package/constructs/ReactStaticSite.js +0 -54
  228. package/constructs/Script/cfn-response.d.ts +0 -19
  229. package/constructs/Script/cfn-response.js +0 -77
  230. package/constructs/Script/index.d.ts +0 -1
  231. package/constructs/Script/index.js +0 -78
  232. package/constructs/Script/outbound.d.ts +0 -10
  233. package/constructs/Script/outbound.js +0 -42
  234. package/constructs/Script/util.d.ts +0 -2
  235. package/constructs/Script/util.js +0 -11
  236. package/constructs/ViteStaticSite.d.ts +0 -32
  237. package/constructs/ViteStaticSite.js +0 -66
  238. package/support/astro-site-html-stub/index.html +0 -99
  239. package/support/base-site-archiver.cjs +0 -116
  240. package/support/nextjs-site-html-stub/index.html +0 -99
  241. package/support/remix-site-html-stub/index.html +0 -99
  242. package/support/solid-start-site-html-stub/index.html +0 -99
  243. package/support/static-site-stub/index.html +0 -90
@@ -9,7 +9,6 @@ import * as ssm from "aws-cdk-lib/aws-ssm";
9
9
  import { Stack } from "./Stack.js";
10
10
  import { Job } from "./Job.js";
11
11
  import { Secret } from "./Config.js";
12
- import { isSSTConstruct } from "./Construct.js";
13
12
  import { toCdkSize } from "./util/size.js";
14
13
  import { toCdkDuration } from "./util/duration.js";
15
14
  import { bindEnvironment, bindPermissions } from "./util/functionBinding.js";
@@ -17,8 +16,7 @@ import { attachPermissionsToRole } from "./util/permission.js";
17
16
  import * as functionUrlCors from "./util/functionUrlCors.js";
18
17
  import url from "url";
19
18
  import { useDeferredTasks } from "./deferred_task.js";
20
- import { useWarning } from "./util/warning.js";
21
- import { useProject } from "../app.js";
19
+ import { useProject } from "../project.js";
22
20
  import { useRuntimeHandlers } from "../runtime/handlers.js";
23
21
  import { createAppContext } from "./context.js";
24
22
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
@@ -77,6 +75,7 @@ export class Function extends lambda.Function {
77
75
  .forEach((per) => {
78
76
  props = Function.mergeProps(per, props);
79
77
  });
78
+ props.runtime = props.runtime || "nodejs16.x";
80
79
  // Set defaults
81
80
  const functionName = props.functionName &&
82
81
  (typeof props.functionName === "string"
@@ -84,7 +83,6 @@ export class Function extends lambda.Function {
84
83
  : props.functionName({ stack, functionProps: props }));
85
84
  const handler = props.handler;
86
85
  const timeout = Function.normalizeTimeout(props.timeout);
87
- const runtime = Function.normalizeRuntime(props.runtime);
88
86
  const architecture = (() => {
89
87
  if (props.architecture === "arm_64")
90
88
  return lambda.Architecture.ARM_64;
@@ -103,9 +101,7 @@ export class Function extends lambda.Function {
103
101
  throw new Error(`No handler defined for the "${id}" Lambda function`);
104
102
  }
105
103
  // Validate input
106
- const isNodeRuntime = runtime.startsWith("nodejs");
107
- const isPythonRuntime = runtime.startsWith("python");
108
- const isJavaRuntime = runtime.startsWith("java");
104
+ const isNodeRuntime = props.runtime.startsWith("nodejs");
109
105
  // Handle local development (ie. sst start)
110
106
  // - set runtime to nodejs12.x for non-Node runtimes (b/c the stub is in Node)
111
107
  // - set retry to 0. When the debugger is disconnected, the Cron construct
@@ -190,13 +186,18 @@ export class Function extends lambda.Function {
190
186
  useDeferredTasks().add(async () => {
191
187
  // Build function
192
188
  const result = await useRuntimeHandlers().build(this.node.addr, "deploy");
193
- if (result.type === "error")
194
- throw new Error(`Failed to build function "${props.handler}"`);
189
+ if (result.type === "error") {
190
+ throw new Error([
191
+ `Failed to build function "${props.handler}"`,
192
+ ...result.errors,
193
+ ].join("\n"));
194
+ }
195
195
  const code = lambda.AssetCode.fromAsset(result.out);
196
196
  // Update function's code
197
197
  const codeConfig = code.bind(this);
198
198
  const cfnFunction = this.node.defaultChild;
199
- cfnFunction.runtime = supportedRuntimes[runtime].toString();
199
+ cfnFunction.runtime =
200
+ supportedRuntimes[props.runtime].toString();
200
201
  /*
201
202
  if (isJavaRuntime) {
202
203
  const providedRuntime = (bundle as FunctionBundleJavaProps)
@@ -229,10 +230,9 @@ export class Function extends lambda.Function {
229
230
  // Add config
230
231
  this.addEnvironment("SST_APP", app.name, { removeInEdge: true });
231
232
  this.addEnvironment("SST_STAGE", app.stage, { removeInEdge: true });
232
- this.addEnvironment("SST_SSM_PREFIX", useProject().ssmPrefix, {
233
+ this.addEnvironment("SST_SSM_PREFIX", useProject().config.ssmPrefix, {
233
234
  removeInEdge: true,
234
235
  });
235
- this.addConfig(props.config || []);
236
236
  this.bind(props.bind || []);
237
237
  this.createUrl();
238
238
  this._isLiveDevEnabled = isLiveDevEnabled;
@@ -268,27 +268,6 @@ export class Function extends lambda.Function {
268
268
  ]));
269
269
  });
270
270
  }
271
- /**
272
- * Attaches additional configs to function.
273
- *
274
- * @deprecated 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/constructs/function
275
- *
276
- * @example
277
- * ```js
278
- * const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY");
279
- *
280
- * // Change
281
- * job.addConfig([STRIPE_KEY]);
282
- *
283
- * // To
284
- * job.bind([STRIPE_KEY]);
285
- * ```
286
- */
287
- addConfig(config) {
288
- this.bind(config);
289
- if (config.length > 0)
290
- useWarning().add("config.deprecated");
291
- }
292
271
  /**
293
272
  * Attaches additional permissions to function.
294
273
  *
@@ -308,20 +287,16 @@ export class Function extends lambda.Function {
308
287
  .filter((p) => p instanceof Job)
309
288
  .forEach((p) => this.bind([p]));
310
289
  }
311
- // Warn user if SST constructs are passed into permissions
312
- if (permissions !== "*" && permissions.some((p) => isSSTConstruct(p))) {
313
- useWarning().add("permissions.noConstructs");
314
- }
315
290
  }
316
291
  /** @internal */
317
292
  getConstructMetadata() {
318
- const { config, bind } = this.props;
293
+ const { bind } = this.props;
319
294
  return {
320
295
  type: "Function",
321
296
  data: {
322
297
  arn: this.functionArn,
323
298
  localId: this.node.addr,
324
- secrets: [...(config || []), ...(bind || [])]
299
+ secrets: (bind || [])
325
300
  .filter((c) => c instanceof Secret)
326
301
  .map((c) => c.name),
327
302
  },
@@ -391,13 +366,6 @@ export class Function extends lambda.Function {
391
366
  }
392
367
  return cdk.Duration.seconds(timeout || 10);
393
368
  }
394
- static normalizeRuntime(runtime) {
395
- runtime = runtime || "nodejs18.x";
396
- if (!supportedRuntimes[runtime]) {
397
- throw new Error(`The specified runtime is not supported for sst.Function. Only NodeJS, Python, Go, and .NET runtimes are currently supported.`);
398
- }
399
- return runtime;
400
- }
401
369
  static normalizeSrcPath(srcPath) {
402
370
  return srcPath.replace(/\/+$/, "");
403
371
  }
@@ -475,9 +443,6 @@ export class Function extends lambda.Function {
475
443
  // Merge layers
476
444
  const layers = [...(baseProps?.layers || []), ...(props?.layers || [])];
477
445
  const layersProp = layers.length === 0 ? {} : { layers };
478
- // Merge config
479
- const config = [...(baseProps?.config || []), ...(props?.config || [])];
480
- const configProp = config.length === 0 ? {} : { config };
481
446
  // Merge bind
482
447
  const bind = [...(baseProps?.bind || []), ...(props?.bind || [])];
483
448
  const bindProp = bind.length === 0 ? {} : { bind };
@@ -497,7 +462,6 @@ export class Function extends lambda.Function {
497
462
  ...(baseProps || {}),
498
463
  ...(props || {}),
499
464
  ...bindProp,
500
- ...configProp,
501
465
  ...layersProp,
502
466
  ...environmentProp,
503
467
  ...permissionsProp,
@@ -6,8 +6,8 @@ export declare function stack(app: App, fn: FunctionalStack<any>, props?: StackP
6
6
  export declare function use<T>(stack: FunctionalStack<T>): T;
7
7
  export declare function dependsOn(stack: FunctionalStack<any>): void;
8
8
  export declare function getStack(stack: FunctionalStack<any>): Stack;
9
- export declare type StackContext = {
9
+ export type StackContext = {
10
10
  app: App;
11
11
  stack: Stack;
12
12
  };
13
- export declare type FunctionalStack<T> = (this: Stack, ctx: StackContext) => T | Promise<T>;
13
+ export type FunctionalStack<T> = (this: Stack, ctx: StackContext) => T | Promise<T>;
@@ -1,11 +1,10 @@
1
1
  import { Construct } from "constructs";
2
- import { Secret, Parameter } from "./Config.js";
3
2
  import { SSTConstruct } from "./Construct.js";
4
3
  import { Function } from "./Function.js";
5
4
  import { Duration } from "./util/duration.js";
6
5
  import { Permissions } from "./util/permission.js";
7
6
  import { IVpc } from "aws-cdk-lib/aws-ec2";
8
- export declare type JobMemorySize = "3 GB" | "7 GB" | "15 GB" | "145 GB";
7
+ export type JobMemorySize = "3 GB" | "7 GB" | "15 GB" | "145 GB";
9
8
  export interface JobProps {
10
9
  /**
11
10
  * Path to the entry point and handler function. Of the format:
@@ -87,27 +86,6 @@ export interface JobProps {
87
86
  * ```
88
87
  */
89
88
  bind?: SSTConstruct[];
90
- /**
91
- * Configure environment variables for the job
92
- *
93
- * @deprecated 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/constructs/function
94
- *
95
- * @example
96
- * ```js
97
- * // Change
98
- * new Job(stack, "MyJob", {
99
- * handler: "src/job.handler",
100
- * config: [STRIPE_KEY, API_URL]
101
- * })
102
- *
103
- * // To
104
- * new Job(stack, "MyJob", {
105
- * handler: "src/job.handler",
106
- * bind: [STRIPE_KEY, API_URL]
107
- * })
108
- * ```
109
- */
110
- config?: (Secret | Parameter)[];
111
89
  /**
112
90
  * Attaches the given list of permissions to the job. Configuring this property is equivalent to calling `attachPermissions()` after the job is created.
113
91
  *
@@ -120,29 +98,28 @@ export interface JobProps {
120
98
  * ```
121
99
  */
122
100
  permissions?: Permissions;
123
- cdk?: JobCDKProps;
124
- }
125
- export interface JobCDKProps {
126
- /**
127
- * Allows you to override default id for this construct.
128
- */
129
- id?: string;
130
- /**
131
- * Runs codebuild job in the specified VPC. Note this will only work once deployed.
132
- *
133
- * @example
134
- * ```js
135
- * new Job(stack, "MyJob", {
136
- * handler: "src/job.handler",
137
- * cdk: {
138
- * vpc: Vpc.fromLookup(this, "VPC", {
139
- * vpcId: "vpc-xxxxxxxxxx",
140
- * }),
141
- * }
142
- * })
143
- * ```
144
- */
145
- vpc?: IVpc;
101
+ cdk?: {
102
+ /**
103
+ * Allows you to override default id for this construct.
104
+ */
105
+ id?: string;
106
+ /**
107
+ * Runs codebuild job in the specified VPC. Note this will only work once deployed.
108
+ *
109
+ * @example
110
+ * ```js
111
+ * new Job(stack, "MyJob", {
112
+ * handler: "src/job.handler",
113
+ * cdk: {
114
+ * vpc: Vpc.fromLookup(stack, "VPC", {
115
+ * vpcId: "vpc-xxxxxxxxxx",
116
+ * }),
117
+ * }
118
+ * })
119
+ * ```
120
+ */
121
+ vpc?: IVpc;
122
+ };
146
123
  }
147
124
  /**
148
125
  * The `Cron` construct is a higher level CDK construct that makes it easy to create a cron job.
@@ -192,23 +169,6 @@ export declare class Job extends Construct implements SSTConstruct {
192
169
  * ```
193
170
  */
194
171
  bind(constructs: SSTConstruct[]): void;
195
- /**
196
- * Attaches additional configs to job.
197
- *
198
- * @deprecated 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/constructs/function
199
- *
200
- * @example
201
- * ```js
202
- * const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY");
203
- *
204
- * // Change
205
- * job.addConfig([STRIPE_KEY]);
206
- *
207
- * // To
208
- * job.bind([STRIPE_KEY]);
209
- * ```
210
- */
211
- addConfig(config: (Secret | Parameter)[]): void;
212
172
  /**
213
173
  * Attaches the given list of [permissions](Permissions.md) to the job. This allows the job to access other AWS resources.
214
174
  *
package/constructs/Job.js CHANGED
@@ -6,13 +6,13 @@ import { Construct } from "constructs";
6
6
  import * as iam from "aws-cdk-lib/aws-iam";
7
7
  import * as lambda from "aws-cdk-lib/aws-lambda";
8
8
  import * as codebuild from "aws-cdk-lib/aws-codebuild";
9
- import { Function } from "./Function.js";
9
+ import { Stack } from "./Stack.js";
10
+ import { Function, useFunctions } from "./Function.js";
10
11
  import { toCdkDuration } from "./util/duration.js";
11
12
  import { attachPermissionsToRole } from "./util/permission.js";
12
13
  import { bindEnvironment, bindPermissions } from "./util/functionBinding.js";
13
14
  import { useDeferredTasks } from "./deferred_task.js";
14
- import { useWarning } from "./util/warning.js";
15
- import { useProject } from "../app.js";
15
+ import { useProject } from "../project.js";
16
16
  import { useRuntimeHandlers } from "../runtime/handlers.js";
17
17
  const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
18
18
  /////////////////////
@@ -44,6 +44,10 @@ export class Job extends Construct {
44
44
  const app = this.node.root;
45
45
  this.id = id;
46
46
  this.props = props;
47
+ useFunctions().add(this.node.addr, {
48
+ ...props,
49
+ runtime: "nodejs16.x",
50
+ });
47
51
  this.localId = path.posix
48
52
  .join(scope.node.path, id)
49
53
  .replace(/\$/g, "-")
@@ -59,7 +63,6 @@ export class Job extends Construct {
59
63
  this.buildCodeBuildProjectCode();
60
64
  }
61
65
  this.attachPermissions(props.permissions || []);
62
- this.addConfig(props.config || []);
63
66
  this.bind(props.bind || []);
64
67
  Object.entries(props.environment || {}).forEach(([key, value]) => {
65
68
  this.addEnvironment(key, value);
@@ -98,29 +101,6 @@ export class Job extends Construct {
98
101
  this._jobInvoker.bind(constructs);
99
102
  this.useForCodeBuild(constructs);
100
103
  }
101
- /**
102
- * Attaches additional configs to job.
103
- *
104
- * @deprecated 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/constructs/function
105
- *
106
- * @example
107
- * ```js
108
- * const STRIPE_KEY = new Config.Secret(stack, "STRIPE_KEY");
109
- *
110
- * // Change
111
- * job.addConfig([STRIPE_KEY]);
112
- *
113
- * // To
114
- * job.bind([STRIPE_KEY]);
115
- * ```
116
- */
117
- addConfig(config) {
118
- const app = this.node.root;
119
- this.bind(config);
120
- if (config.length > 0) {
121
- useWarning().add("config.deprecated");
122
- }
123
- }
124
104
  /**
125
105
  * Attaches the given list of [permissions](Permissions.md) to the job. This allows the job to access other AWS resources.
126
106
  *
@@ -165,7 +145,7 @@ export class Job extends Construct {
165
145
  environmentVariables: {
166
146
  SST_APP: { value: app.name },
167
147
  SST_STAGE: { value: app.stage },
168
- SST_SSM_PREFIX: { value: useProject().ssmPrefix },
148
+ SST_SSM_PREFIX: { value: useProject().config.ssmPrefix },
169
149
  },
170
150
  timeout: this.normalizeTimeout(this.props.timeout || "8 hours"),
171
151
  buildSpec: codebuild.BuildSpec.fromObject({
@@ -252,13 +232,13 @@ export class Job extends Construct {
252
232
  actions: ["s3:*"],
253
233
  effect: iam.Effect.ALLOW,
254
234
  resources: [
255
- `arn:aws:s3:::${codeConfig.s3Location?.bucketName}/${codeConfig.s3Location?.objectKey}`,
235
+ `arn:${Stack.of(this).partition}:s3:::${codeConfig.s3Location?.bucketName}/${codeConfig.s3Location?.objectKey}`,
256
236
  ],
257
237
  }),
258
238
  ]);
259
239
  }
260
240
  createLocalInvoker() {
261
- const { handler, config, environment, permissions } = this.props;
241
+ const { handler, permissions } = this.props;
262
242
  // Note: make the invoker function the same ID as the Job
263
243
  // construct so users can identify the invoker function
264
244
  // in the Console.
@@ -268,7 +248,6 @@ export class Job extends Construct {
268
248
  runtime: "nodejs16.x",
269
249
  timeout: 10,
270
250
  memorySize: 1024,
271
- config,
272
251
  environment: {
273
252
  SST_DEBUG_TYPE: "job",
274
253
  },
@@ -279,7 +258,7 @@ export class Job extends Construct {
279
258
  }
280
259
  createCodeBuildInvoker() {
281
260
  return new Function(this, this.node.id, {
282
- handler: path.join(__dirname, "../dist/support/job-invoke/index.main"),
261
+ handler: path.join(__dirname, "../support/job-invoker/index.main"),
283
262
  runtime: "nodejs16.x",
284
263
  timeout: 10,
285
264
  memorySize: 1024,
@@ -1,42 +1,40 @@
1
1
  import { SSTConstruct } from "./Construct.js";
2
- declare type ExtractMetadata<T extends SSTConstruct> = ReturnType<T["getConstructMetadata"]> & {
2
+ type ExtractMetadata<T extends SSTConstruct> = ReturnType<T["getConstructMetadata"]> & {
3
3
  id: string;
4
4
  addr: string;
5
5
  stack: string;
6
6
  };
7
7
  import type { Api } from "./Api.js";
8
- export declare type ApiMetadata = ExtractMetadata<Api<any>>;
9
- import { GraphQLApi } from "./GraphQLApi.js";
10
- export declare type GraphQLApiMetadata = ExtractMetadata<GraphQLApi>;
8
+ export type ApiMetadata = ExtractMetadata<Api<any>>;
11
9
  import type { ApiGatewayV1Api } from "./ApiGatewayV1Api.js";
12
- export declare type ApiGatewayV1ApiMetadata = ExtractMetadata<ApiGatewayV1Api<any>>;
10
+ export type ApiGatewayV1ApiMetadata = ExtractMetadata<ApiGatewayV1Api<any>>;
13
11
  import type { Cognito } from "./Cognito.js";
14
- export declare type AuthMetadata = ExtractMetadata<Cognito>;
12
+ export type AuthMetadata = ExtractMetadata<Cognito>;
15
13
  import type { AppSyncApi } from "./AppSyncApi.js";
16
- export declare type AppSyncApiMetadata = ExtractMetadata<AppSyncApi>;
14
+ export type AppSyncApiMetadata = ExtractMetadata<AppSyncApi>;
17
15
  import type { Bucket } from "./Bucket.js";
18
- export declare type BucketMetadata = ExtractMetadata<Bucket>;
16
+ export type BucketMetadata = ExtractMetadata<Bucket>;
19
17
  import type { Cron } from "./Cron.js";
20
- export declare type CronMetadata = ExtractMetadata<Cron>;
18
+ export type CronMetadata = ExtractMetadata<Cron>;
21
19
  import type { EventBus } from "./EventBus.js";
22
- export declare type EventBusMetadata = ExtractMetadata<EventBus>;
20
+ export type EventBusMetadata = ExtractMetadata<EventBus>;
23
21
  import type { Function as Fn } from "./Function.js";
24
- export declare type FunctionMetadata = ExtractMetadata<Fn>;
22
+ export type FunctionMetadata = ExtractMetadata<Fn>;
25
23
  import type { KinesisStream } from "./KinesisStream.js";
26
- export declare type KinesisStreamMetadata = ExtractMetadata<KinesisStream>;
24
+ export type KinesisStreamMetadata = ExtractMetadata<KinesisStream>;
27
25
  import type { NextjsSite } from "./NextjsSite.js";
28
- export declare type NextjsMetadata = ExtractMetadata<NextjsSite>;
26
+ export type NextjsMetadata = ExtractMetadata<NextjsSite>;
29
27
  import type { Queue } from "./Queue.js";
30
- export declare type QueueMetadata = ExtractMetadata<Queue>;
28
+ export type QueueMetadata = ExtractMetadata<Queue>;
31
29
  import type { StaticSite } from "./StaticSite.js";
32
- export declare type StaticSiteMetadata = ExtractMetadata<StaticSite>;
30
+ export type StaticSiteMetadata = ExtractMetadata<StaticSite>;
33
31
  import type { Table } from "./Table.js";
34
- export declare type TableMetadata = ExtractMetadata<Table>;
32
+ export type TableMetadata = ExtractMetadata<Table>;
35
33
  import type { Topic } from "./Topic.js";
36
- export declare type TopicMetadata = ExtractMetadata<Topic>;
34
+ export type TopicMetadata = ExtractMetadata<Topic>;
37
35
  import type { WebSocketApi } from "./WebSocketApi.js";
38
- export declare type WebSocketApiMetadata = ExtractMetadata<WebSocketApi>;
36
+ export type WebSocketApiMetadata = ExtractMetadata<WebSocketApi>;
39
37
  import type { RDS } from "./RDS.js";
40
- export declare type RDSMetadata = ExtractMetadata<RDS>;
41
- export declare type Metadata = ApiMetadata | ApiGatewayV1ApiMetadata | AuthMetadata | AppSyncApiMetadata | BucketMetadata | CronMetadata | EventBusMetadata | FunctionMetadata | KinesisStreamMetadata | NextjsMetadata | QueueMetadata | StaticSiteMetadata | TableMetadata | TopicMetadata | WebSocketApiMetadata | GraphQLApiMetadata | RDSMetadata;
38
+ export type RDSMetadata = ExtractMetadata<RDS>;
39
+ export type Metadata = ApiMetadata | ApiGatewayV1ApiMetadata | AuthMetadata | AppSyncApiMetadata | BucketMetadata | CronMetadata | EventBusMetadata | FunctionMetadata | KinesisStreamMetadata | NextjsMetadata | QueueMetadata | StaticSiteMetadata | TableMetadata | TopicMetadata | WebSocketApiMetadata | RDSMetadata;
42
40
  export {};
@@ -2,7 +2,20 @@ import { Construct } from "constructs";
2
2
  import * as lambda from "aws-cdk-lib/aws-lambda";
3
3
  import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
4
4
  import { SsrSite, SsrSiteProps } from "./SsrSite.js";
5
+ import { Size } from "./util/size.js";
6
+ import { Duration } from "./util/duration.js";
5
7
  export interface NextjsSiteProps extends Omit<SsrSiteProps, "edge"> {
8
+ imageOptimization?: {
9
+ /**
10
+ * The amount of memory in MB allocated for image optimization function.
11
+ * @default 1024 MB
12
+ * @example
13
+ * ```js
14
+ * memorySize: "512 MB",
15
+ * ```
16
+ */
17
+ memorySize?: number | Size;
18
+ };
6
19
  }
7
20
  /**
8
21
  * The `NextjsSite` construct is a higher level CDK construct that makes it easy to create a Next.js app.
@@ -16,18 +29,21 @@ export interface NextjsSiteProps extends Omit<SsrSiteProps, "edge"> {
16
29
  * ```
17
30
  */
18
31
  export declare class NextjsSite extends SsrSite {
19
- constructor(scope: Construct, id: string, props: NextjsSiteProps);
32
+ protected props: Omit<NextjsSiteProps, "path"> & {
33
+ path: string;
34
+ timeout: number | Duration;
35
+ memorySize: number | Size;
36
+ };
37
+ constructor(scope: Construct, id: string, props?: NextjsSiteProps);
20
38
  protected initBuildConfig(): {
21
39
  serverBuildOutputFile: string;
22
40
  clientBuildOutputDir: string;
23
41
  clientBuildVersionedSubDir: string;
24
- siteStub: string;
25
42
  };
26
43
  protected createFunctionForRegional(): lambda.Function;
44
+ private createImageOptimizationFunctionForRegional;
45
+ private createMiddlewareEdgeFunctionForRegional;
27
46
  protected createCloudFrontDistributionForRegional(): cloudfront.Distribution;
28
- protected createCloudFrontDistributionForStub(): cloudfront.Distribution;
29
47
  protected createCloudFrontServerCachePolicy(): cloudfront.CachePolicy;
30
48
  protected generateBuildId(): string;
31
- private createImageOptimizationFunctionForRegional;
32
- private createMiddlewareEdgeFunctionForRegional;
33
49
  }