sst 2.0.0-rc.9 → 2.0.1
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/bootstrap.d.ts +2 -4
- package/bootstrap.js +208 -61
- package/bus.d.ts +3 -3
- package/bus.js +1 -1
- package/cache.js +1 -1
- package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
- package/cdk/cloudformation-deployments-wrapper.js +117 -0
- package/cdk/cloudformation-deployments.d.ts +19 -4
- package/cdk/deploy-stack.d.ts +17 -2
- package/cdk/deploy-stack.js +6 -1
- package/cli/colors.d.ts +28 -0
- package/cli/colors.js +27 -0
- package/cli/commands/bind.d.ts +4 -0
- package/cli/commands/bind.js +10 -7
- package/cli/commands/bootstrap.d.ts +13 -0
- package/cli/commands/bootstrap.js +11 -0
- package/cli/commands/build.d.ts +6 -2
- package/cli/commands/build.js +13 -8
- package/cli/commands/console.d.ts +5 -1
- package/cli/commands/console.js +8 -6
- package/cli/commands/deploy.d.ts +4 -2
- package/cli/commands/deploy.js +69 -29
- package/cli/commands/dev.d.ts +5 -1
- package/cli/commands/dev.js +157 -79
- package/cli/commands/diff.d.ts +15 -0
- package/cli/commands/diff.js +61 -0
- package/cli/commands/env.d.ts +5 -1
- package/cli/commands/env.js +14 -15
- package/cli/commands/plugins/kysely.js +13 -5
- package/cli/commands/plugins/pothos.js +9 -4
- package/cli/commands/remove.d.ts +4 -0
- package/cli/commands/remove.js +26 -18
- package/cli/commands/secrets/get.d.ts +7 -3
- package/cli/commands/secrets/get.js +11 -24
- package/cli/commands/secrets/list.d.ts +6 -2
- package/cli/commands/secrets/list.js +15 -7
- package/cli/commands/secrets/remove.d.ts +8 -4
- package/cli/commands/secrets/remove.js +18 -16
- package/cli/commands/secrets/secrets.js +3 -3
- package/cli/commands/secrets/set.d.ts +8 -6
- package/cli/commands/secrets/set.js +16 -33
- package/cli/commands/telemetry.d.ts +15 -0
- package/cli/commands/telemetry.js +17 -0
- package/cli/commands/transform.d.ts +15 -0
- package/cli/commands/transform.js +55 -0
- package/cli/commands/update.d.ts +6 -2
- package/cli/commands/update.js +41 -33
- package/cli/commands/version.d.ts +13 -0
- package/cli/commands/version.js +7 -0
- package/cli/local/router.d.ts +6 -6
- package/cli/local/router.js +3 -3
- package/cli/local/server.d.ts +5 -3
- package/cli/local/server.js +21 -14
- package/cli/program.d.ts +5 -1
- package/cli/program.js +29 -5
- package/cli/spinner.js +2 -0
- package/cli/sst.js +35 -23
- package/cli/telemetry/environment.d.ts +1 -1
- package/cli/telemetry/environment.js +1 -1
- package/cli/terminal.d.ts +1 -0
- package/cli/terminal.js +8 -0
- package/cli/ui/deploy.d.ts +3 -2
- package/cli/ui/deploy.js +106 -106
- package/cli/ui/functions.d.ts +2 -0
- package/cli/ui/functions.js +132 -0
- package/cli/ui/header.d.ts +5 -0
- package/cli/ui/header.js +16 -0
- package/cli/ui/stack.d.ts +1 -0
- package/cli/ui/stack.js +6 -0
- package/config.d.ts +1 -1
- package/config.js +8 -8
- package/constructs/Api.d.ts +3 -71
- package/constructs/Api.js +3 -42
- package/constructs/ApiGatewayV1Api.d.ts +3 -3
- package/constructs/ApiGatewayV1Api.js +4 -3
- package/constructs/App.d.ts +2 -22
- package/constructs/App.js +12 -25
- package/constructs/AppSyncApi.d.ts +4 -5
- package/constructs/AppSyncApi.js +8 -5
- package/constructs/AstroSite.d.ts +2 -3
- package/constructs/AstroSite.js +43 -53
- package/constructs/Auth.js +27 -16
- package/constructs/BaseSite.d.ts +10 -10
- package/constructs/BaseSite.js +2 -2
- package/constructs/Cognito.js +28 -28
- package/constructs/EdgeFunction.d.ts +6 -4
- package/constructs/EdgeFunction.js +56 -59
- package/constructs/EventBus.js +1 -1
- package/constructs/Function.d.ts +4 -44
- package/constructs/Function.js +14 -50
- package/constructs/FunctionalStack.d.ts +2 -2
- package/constructs/Job.d.ts +23 -63
- package/constructs/Job.js +11 -32
- package/constructs/Metadata.d.ts +18 -20
- package/constructs/NextjsSite.d.ts +21 -5
- package/constructs/NextjsSite.js +67 -101
- package/constructs/Queue.js +10 -10
- package/constructs/RDS.d.ts +1 -1
- package/constructs/RDS.js +1 -1
- package/constructs/RemixSite.d.ts +0 -2
- package/constructs/RemixSite.js +20 -20
- package/constructs/Script.js +1 -1
- package/constructs/Secret.js +5 -3
- package/constructs/SolidStartSite.d.ts +2 -3
- package/constructs/SolidStartSite.js +42 -52
- package/constructs/SsrFunction.d.ts +22 -0
- package/constructs/SsrFunction.js +113 -0
- package/constructs/SsrSite.d.ts +104 -104
- package/constructs/SsrSite.js +196 -217
- package/constructs/Stack.d.ts +1 -20
- package/constructs/Stack.js +3 -65
- package/constructs/StaticSite.d.ts +33 -53
- package/constructs/StaticSite.js +92 -118
- package/constructs/Table.d.ts +1 -1
- package/constructs/Table.js +4 -4
- package/constructs/Topic.js +1 -1
- package/constructs/cdk/certificate-base.d.ts +18 -0
- package/constructs/cdk/certificate-base.js +26 -0
- package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
- package/constructs/cdk/dns-validated-certificate.js +125 -0
- package/constructs/cdk/website-redirect.d.ts +53 -0
- package/constructs/cdk/website-redirect.js +77 -0
- package/constructs/deferred_task.d.ts +1 -1
- package/constructs/deprecated/NextjsSite.js +8 -6
- package/constructs/index.d.ts +0 -6
- package/constructs/index.js +0 -6
- package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
- package/constructs/util/apiGatewayV2AccessLog.js +4 -4
- package/constructs/util/apiGatewayV2Domain.js +9 -2
- package/constructs/util/appSyncApiDomain.d.ts +1 -1
- package/constructs/util/appSyncApiDomain.js +9 -15
- package/constructs/util/duration.d.ts +1 -1
- package/constructs/util/functionBinding.js +1 -1
- package/constructs/util/permission.d.ts +3 -3
- package/constructs/util/permission.js +16 -18
- package/constructs/util/size.d.ts +1 -1
- package/constructs/util/warning.js +2 -2
- package/context/context.d.ts +2 -2
- package/context/context.js +4 -4
- package/context/handler.d.ts +1 -1
- package/credentials.d.ts +1 -1
- package/credentials.js +42 -6
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/iot.js +6 -2
- package/logger.js +3 -1
- package/node/api/index.d.ts +2 -3
- package/node/api/index.js +8 -2
- package/node/auth/adapter/adapter.d.ts +1 -1
- package/node/auth/adapter/facebook.js +1 -1
- package/node/auth/adapter/github.js +4 -4
- package/node/auth/adapter/google.d.ts +1 -1
- package/node/auth/adapter/google.js +2 -2
- package/node/auth/adapter/twitch.js +1 -1
- package/node/auth/session.d.ts +1 -1
- package/node/config/index.d.ts +2 -2
- package/node/config/index.js +3 -8
- package/node/job/index.d.ts +2 -2
- package/node/site/index.js +3 -5
- package/package.json +26 -21
- package/pothos.js +1 -0
- package/project.d.ts +47 -0
- package/{app.js → project.js} +60 -53
- package/runtime/handlers/dotnet.d.ts +1 -1
- package/runtime/handlers/dotnet.js +4 -4
- package/runtime/handlers/go.d.ts +1 -1
- package/runtime/handlers/go.js +3 -3
- package/runtime/handlers/java.d.ts +1 -1
- package/runtime/handlers/java.js +4 -4
- package/runtime/handlers/node.d.ts +1 -1
- package/runtime/handlers/node.js +60 -39
- package/runtime/handlers/python.d.ts +1 -1
- package/runtime/handlers/python.js +3 -3
- package/runtime/handlers.js +15 -12
- package/runtime/iot.js +3 -0
- package/runtime/runtime.d.ts +4 -0
- package/runtime/server.d.ts +3 -3
- package/runtime/server.js +11 -5
- package/runtime/workers.d.ts +4 -2
- package/runtime/workers.js +13 -3
- package/site-env.js +2 -1
- package/sst.mjs +6357 -20848
- package/stacks/app-metadata.d.ts +7 -0
- package/stacks/app-metadata.js +78 -0
- package/stacks/assembly.d.ts +1 -0
- package/stacks/assembly.js +4 -0
- package/stacks/build.d.ts +1 -1
- package/stacks/build.js +41 -48
- package/stacks/deploy.d.ts +1 -0
- package/stacks/deploy.js +128 -7
- package/stacks/diff.d.ts +8 -0
- package/stacks/diff.js +62 -0
- package/stacks/index.d.ts +3 -0
- package/stacks/index.js +3 -0
- package/stacks/metadata.d.ts +2 -0
- package/stacks/metadata.js +14 -12
- package/stacks/monitor.d.ts +8 -3
- package/stacks/monitor.js +38 -4
- package/stacks/remove.js +0 -4
- package/stacks/synth.d.ts +1 -0
- package/stacks/synth.js +27 -13
- package/support/base-site-archiver.mjs +1 -1
- package/support/bootstrap-metadata-function/index.mjs +68740 -0
- package/support/bridge/bridge.mjs +28 -28
- package/support/certificate-requestor/index.js +549 -0
- package/support/custom-resources/index.mjs +3824 -26567
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
- package/support/edge-function/edge-lambda.mjs +2 -2
- package/support/job-invoker/index.mjs +26 -0
- package/support/nodejs-runtime/index.mjs +75 -72
- package/support/rds-migrator/index.mjs +22 -23
- package/support/remix-site-function/edge-server.js +1 -1
- package/support/script-function/index.mjs +30485 -0
- package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
- package/support/ssr-site-function-archiver.mjs +96 -0
- package/watcher.js +1 -1
- package/app.d.ts +0 -36
- package/constructs/DebugApp.d.ts +0 -49
- package/constructs/DebugApp.js +0 -63
- package/constructs/DebugStack.d.ts +0 -34
- package/constructs/DebugStack.js +0 -132
- package/constructs/GraphQLApi.d.ts +0 -98
- package/constructs/GraphQLApi.js +0 -80
- package/constructs/ReactStaticSite.d.ts +0 -20
- package/constructs/ReactStaticSite.js +0 -54
- package/constructs/Script/cfn-response.d.ts +0 -19
- package/constructs/Script/cfn-response.js +0 -77
- package/constructs/Script/index.d.ts +0 -1
- package/constructs/Script/index.js +0 -78
- package/constructs/Script/outbound.d.ts +0 -10
- package/constructs/Script/outbound.js +0 -42
- package/constructs/Script/util.d.ts +0 -2
- package/constructs/Script/util.js +0 -11
- package/constructs/ViteStaticSite.d.ts +0 -32
- package/constructs/ViteStaticSite.js +0 -66
- package/support/astro-site-html-stub/index.html +0 -99
- package/support/base-site-archiver.cjs +0 -116
- package/support/nextjs-site-html-stub/index.html +0 -99
- package/support/remix-site-html-stub/index.html +0 -99
- package/support/solid-start-site-html-stub/index.html +0 -99
- package/support/static-site-stub/index.html +0 -90
package/constructs/Function.js
CHANGED
|
@@ -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 {
|
|
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(
|
|
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 =
|
|
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 {
|
|
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:
|
|
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
|
|
9
|
+
export type StackContext = {
|
|
10
10
|
app: App;
|
|
11
11
|
stack: Stack;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type FunctionalStack<T> = (this: Stack, ctx: StackContext) => T | Promise<T>;
|
package/constructs/Job.d.ts
CHANGED
|
@@ -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
|
|
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?:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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 {
|
|
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 {
|
|
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:
|
|
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,
|
|
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, "../
|
|
261
|
+
handler: path.join(__dirname, "../support/job-invoker/index.main"),
|
|
283
262
|
runtime: "nodejs16.x",
|
|
284
263
|
timeout: 10,
|
|
285
264
|
memorySize: 1024,
|
package/constructs/Metadata.d.ts
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
import { SSTConstruct } from "./Construct.js";
|
|
2
|
-
|
|
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
|
|
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
|
|
10
|
+
export type ApiGatewayV1ApiMetadata = ExtractMetadata<ApiGatewayV1Api<any>>;
|
|
13
11
|
import type { Cognito } from "./Cognito.js";
|
|
14
|
-
export
|
|
12
|
+
export type AuthMetadata = ExtractMetadata<Cognito>;
|
|
15
13
|
import type { AppSyncApi } from "./AppSyncApi.js";
|
|
16
|
-
export
|
|
14
|
+
export type AppSyncApiMetadata = ExtractMetadata<AppSyncApi>;
|
|
17
15
|
import type { Bucket } from "./Bucket.js";
|
|
18
|
-
export
|
|
16
|
+
export type BucketMetadata = ExtractMetadata<Bucket>;
|
|
19
17
|
import type { Cron } from "./Cron.js";
|
|
20
|
-
export
|
|
18
|
+
export type CronMetadata = ExtractMetadata<Cron>;
|
|
21
19
|
import type { EventBus } from "./EventBus.js";
|
|
22
|
-
export
|
|
20
|
+
export type EventBusMetadata = ExtractMetadata<EventBus>;
|
|
23
21
|
import type { Function as Fn } from "./Function.js";
|
|
24
|
-
export
|
|
22
|
+
export type FunctionMetadata = ExtractMetadata<Fn>;
|
|
25
23
|
import type { KinesisStream } from "./KinesisStream.js";
|
|
26
|
-
export
|
|
24
|
+
export type KinesisStreamMetadata = ExtractMetadata<KinesisStream>;
|
|
27
25
|
import type { NextjsSite } from "./NextjsSite.js";
|
|
28
|
-
export
|
|
26
|
+
export type NextjsMetadata = ExtractMetadata<NextjsSite>;
|
|
29
27
|
import type { Queue } from "./Queue.js";
|
|
30
|
-
export
|
|
28
|
+
export type QueueMetadata = ExtractMetadata<Queue>;
|
|
31
29
|
import type { StaticSite } from "./StaticSite.js";
|
|
32
|
-
export
|
|
30
|
+
export type StaticSiteMetadata = ExtractMetadata<StaticSite>;
|
|
33
31
|
import type { Table } from "./Table.js";
|
|
34
|
-
export
|
|
32
|
+
export type TableMetadata = ExtractMetadata<Table>;
|
|
35
33
|
import type { Topic } from "./Topic.js";
|
|
36
|
-
export
|
|
34
|
+
export type TopicMetadata = ExtractMetadata<Topic>;
|
|
37
35
|
import type { WebSocketApi } from "./WebSocketApi.js";
|
|
38
|
-
export
|
|
36
|
+
export type WebSocketApiMetadata = ExtractMetadata<WebSocketApi>;
|
|
39
37
|
import type { RDS } from "./RDS.js";
|
|
40
|
-
export
|
|
41
|
-
export
|
|
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
|
-
|
|
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
|
}
|