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.
- 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 +71 -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 +4 -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 -20846
- 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/util/process.d.ts +0 -1
- 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/Api.js
CHANGED
|
@@ -127,9 +127,7 @@ export class Api extends Construct {
|
|
|
127
127
|
const route = this.routesData[this.normalizeRouteKey(routeKey)];
|
|
128
128
|
if (!route)
|
|
129
129
|
return;
|
|
130
|
-
if (route.type === "function" ||
|
|
131
|
-
route.type === "pothos" ||
|
|
132
|
-
route.type === "graphql") {
|
|
130
|
+
if (route.type === "function" || route.type === "graphql") {
|
|
133
131
|
return route.function;
|
|
134
132
|
}
|
|
135
133
|
}
|
|
@@ -144,9 +142,7 @@ export class Api extends Construct {
|
|
|
144
142
|
*/
|
|
145
143
|
bind(constructs) {
|
|
146
144
|
for (const route of Object.values(this.routesData)) {
|
|
147
|
-
if (route.type === "function" ||
|
|
148
|
-
route.type === "pothos" ||
|
|
149
|
-
route.type === "graphql") {
|
|
145
|
+
if (route.type === "function" || route.type === "graphql") {
|
|
150
146
|
route.function.bind(constructs);
|
|
151
147
|
}
|
|
152
148
|
}
|
|
@@ -185,9 +181,7 @@ export class Api extends Construct {
|
|
|
185
181
|
*/
|
|
186
182
|
attachPermissions(permissions) {
|
|
187
183
|
for (const route of Object.values(this.routesData)) {
|
|
188
|
-
if (route.type === "function" ||
|
|
189
|
-
route.type === "pothos" ||
|
|
190
|
-
route.type === "graphql") {
|
|
184
|
+
if (route.type === "function" || route.type === "graphql") {
|
|
191
185
|
route.function.attachPermissions(permissions);
|
|
192
186
|
}
|
|
193
187
|
}
|
|
@@ -230,15 +224,6 @@ export class Api extends Construct {
|
|
|
230
224
|
route: key,
|
|
231
225
|
fn: getFunctionRef(data.function),
|
|
232
226
|
};
|
|
233
|
-
if (data.type === "pothos")
|
|
234
|
-
return {
|
|
235
|
-
type: "pothos",
|
|
236
|
-
route: key,
|
|
237
|
-
fn: getFunctionRef(data.function),
|
|
238
|
-
schema: data.schema,
|
|
239
|
-
output: data.output,
|
|
240
|
-
commands: data.commands,
|
|
241
|
-
};
|
|
242
227
|
if (data.type === "graphql")
|
|
243
228
|
return {
|
|
244
229
|
type: "graphql",
|
|
@@ -465,12 +450,6 @@ export class Api extends Construct {
|
|
|
465
450
|
this.createHttpIntegration(scope, routeKey, routeValue, postfixName),
|
|
466
451
|
];
|
|
467
452
|
}
|
|
468
|
-
if (routeValue.type === "pothos") {
|
|
469
|
-
return [
|
|
470
|
-
routeValue,
|
|
471
|
-
this.createPothosIntegration(scope, routeKey, routeValue, postfixName),
|
|
472
|
-
];
|
|
473
|
-
}
|
|
474
453
|
if (routeValue.type === "graphql") {
|
|
475
454
|
return [
|
|
476
455
|
routeValue,
|
|
@@ -541,24 +520,6 @@ export class Api extends Construct {
|
|
|
541
520
|
};
|
|
542
521
|
return integration;
|
|
543
522
|
}
|
|
544
|
-
createPothosIntegration(scope, routeKey, routeProps, postfixName) {
|
|
545
|
-
const result = this.createFunctionIntegration(scope, routeKey, {
|
|
546
|
-
...routeProps,
|
|
547
|
-
type: "function",
|
|
548
|
-
payloadFormatVersion: "2.0",
|
|
549
|
-
}, postfixName);
|
|
550
|
-
const data = this.routesData[routeKey];
|
|
551
|
-
if (data.type === "function") {
|
|
552
|
-
this.routesData[routeKey] = {
|
|
553
|
-
...data,
|
|
554
|
-
type: "pothos",
|
|
555
|
-
output: routeProps.output,
|
|
556
|
-
schema: routeProps.schema,
|
|
557
|
-
commands: routeProps.commands,
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
523
|
createGraphQLIntegration(scope, routeKey, routeProps, postfixName) {
|
|
563
524
|
const result = this.createFunctionIntegration(scope, routeKey, {
|
|
564
525
|
...routeProps,
|
|
@@ -203,7 +203,7 @@ export interface ApiGatewayV1ApiProps<Authorizers extends Record<string, ApiGate
|
|
|
203
203
|
};
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
|
-
export
|
|
206
|
+
export type ApiGatewayV1ApiRouteProps<AuthorizerKeys> = FunctionInlineDefinition | ApiGatewayV1ApiFunctionRouteProps<AuthorizerKeys>;
|
|
207
207
|
/**
|
|
208
208
|
* Specify a function route handler and configure additional options
|
|
209
209
|
*
|
|
@@ -230,7 +230,7 @@ export interface ApiGatewayV1ApiFunctionRouteProps<AuthorizerKeys = never> {
|
|
|
230
230
|
function?: lambda.IFunction;
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
-
export
|
|
233
|
+
export type ApiGatewayV1ApiAuthorizer = ApiGatewayV1ApiUserPoolsAuthorizer | ApiGatewayV1ApiLambdaTokenAuthorizer | ApiGatewayV1ApiLambdaRequestAuthorizer;
|
|
234
234
|
interface ApiGatewayV1ApiBaseAuthorizer {
|
|
235
235
|
/**
|
|
236
236
|
* The name of the authorizer.
|
|
@@ -491,7 +491,7 @@ export declare class ApiGatewayV1Api<Authorizers extends Record<string, ApiGatew
|
|
|
491
491
|
/**
|
|
492
492
|
* The internally created certificate
|
|
493
493
|
*/
|
|
494
|
-
certificate?: acm.
|
|
494
|
+
certificate?: acm.ICertificate;
|
|
495
495
|
};
|
|
496
496
|
private _deployment?;
|
|
497
497
|
private _customDomainUrl?;
|
|
@@ -9,6 +9,7 @@ import * as apigV1AccessLog from "./util/apiGatewayV1AccessLog.js";
|
|
|
9
9
|
import { Stack } from "./Stack.js";
|
|
10
10
|
import { toCdkDuration } from "./util/duration.js";
|
|
11
11
|
import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
12
|
+
import { DnsValidatedCertificate } from "./cdk/dns-validated-certificate.js";
|
|
12
13
|
import { Function as Fn, } from "./Function.js";
|
|
13
14
|
const allowedMethods = [
|
|
14
15
|
"ANY",
|
|
@@ -447,7 +448,7 @@ export class ApiGatewayV1Api extends Construct {
|
|
|
447
448
|
/////////////////////
|
|
448
449
|
if (!apigDomainName && !certificate) {
|
|
449
450
|
if (endpointType === "edge") {
|
|
450
|
-
certificate = new
|
|
451
|
+
certificate = new DnsValidatedCertificate(this, "CrossRegionCertificate", {
|
|
451
452
|
domainName: domainName,
|
|
452
453
|
hostedZone: hostedZone,
|
|
453
454
|
region: "us-east-1",
|
|
@@ -665,7 +666,7 @@ export class ApiGatewayV1Api extends Construct {
|
|
|
665
666
|
const [routeProps, lambda] = (() => {
|
|
666
667
|
if (Fn.isInlineDefinition(routeValue)) {
|
|
667
668
|
const routeProps = {
|
|
668
|
-
function: routeValue
|
|
669
|
+
function: routeValue,
|
|
669
670
|
};
|
|
670
671
|
return [
|
|
671
672
|
routeProps,
|
|
@@ -709,7 +710,7 @@ export class ApiGatewayV1Api extends Construct {
|
|
|
709
710
|
const root = scope.node.root;
|
|
710
711
|
if (root.local) {
|
|
711
712
|
lambda.addEnvironment("SST_DEBUG_IS_API_ROUTE", "1", {
|
|
712
|
-
removeInEdge: true
|
|
713
|
+
removeInEdge: true,
|
|
713
714
|
});
|
|
714
715
|
}
|
|
715
716
|
this.functions[routeKey] = lambda;
|
package/constructs/App.d.ts
CHANGED
|
@@ -3,11 +3,9 @@ import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
|
3
3
|
import * as cxapi from "aws-cdk-lib/cx-api";
|
|
4
4
|
import { SSTConstruct } from "./Construct.js";
|
|
5
5
|
import { FunctionProps } from "./Function.js";
|
|
6
|
-
import * as Config from "./Config.js";
|
|
7
6
|
import { Permissions } from "./util/permission.js";
|
|
8
7
|
import { StackProps } from "./Stack.js";
|
|
9
8
|
import { FunctionalStack } from "./FunctionalStack.js";
|
|
10
|
-
import { useBootstrap } from "../bootstrap.js";
|
|
11
9
|
/**
|
|
12
10
|
* @internal
|
|
13
11
|
*/
|
|
@@ -40,10 +38,9 @@ export interface AppDeployProps {
|
|
|
40
38
|
readonly debugBridge?: string;
|
|
41
39
|
readonly debugIncreaseTimeout?: boolean;
|
|
42
40
|
readonly mode: "deploy" | "dev" | "remove";
|
|
43
|
-
readonly bootstrap: Awaited<ReturnType<typeof useBootstrap>>;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
export
|
|
42
|
+
type AppRemovalPolicy = Lowercase<keyof typeof cdk.RemovalPolicy>;
|
|
43
|
+
export type AppProps = cdk.AppProps;
|
|
47
44
|
/**
|
|
48
45
|
* The App construct extends cdk.App and is used internally by SST.
|
|
49
46
|
*/
|
|
@@ -87,8 +84,6 @@ export declare class App extends cdk.App {
|
|
|
87
84
|
/** @internal */
|
|
88
85
|
readonly appPath: string;
|
|
89
86
|
/** @internal */
|
|
90
|
-
readonly bootstrap: AppDeployProps["bootstrap"];
|
|
91
|
-
/** @internal */
|
|
92
87
|
defaultFunctionProps: (FunctionProps | ((stack: cdk.Stack) => FunctionProps))[];
|
|
93
88
|
private _defaultRemovalPolicy?;
|
|
94
89
|
/** @internal */
|
|
@@ -164,21 +159,6 @@ export declare class App extends cdk.App {
|
|
|
164
159
|
* ```
|
|
165
160
|
*/
|
|
166
161
|
addDefaultFunctionEnv(environment: Record<string, string>): void;
|
|
167
|
-
/**
|
|
168
|
-
* Adds additional default config to be applied to all Lambda functions in the app.
|
|
169
|
-
*
|
|
170
|
-
* @deprecated The "addDefaultFunctionConfig" method will be removed in SST v2. Pass Parameters and Secrets in through the "addDefaultFunctionBinding" function. Read more about how to upgrade here — https://docs.serverless-stack.com/upgrade-guide#upgrade-to-v116
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```js
|
|
174
|
-
* // Change
|
|
175
|
-
* app.addDefaultFunctionConfig([STRIPE_KEY]);
|
|
176
|
-
*
|
|
177
|
-
* // To
|
|
178
|
-
* app.addDefaultFunctionBinding([STRIPE_KEY]);
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
addDefaultFunctionConfig(config: (Config.Secret | Config.Parameter)[]): void;
|
|
182
162
|
/**
|
|
183
163
|
* Binds additional default resources to be applied to all Lambda functions in the app.
|
|
184
164
|
*
|
package/constructs/App.js
CHANGED
|
@@ -14,7 +14,7 @@ import { createRequire } from "module";
|
|
|
14
14
|
import { Auth } from "./Auth.js";
|
|
15
15
|
import { useDeferredTasks } from "./deferred_task.js";
|
|
16
16
|
import { AppContext } from "./context.js";
|
|
17
|
-
import { useProject } from "../
|
|
17
|
+
import { useProject } from "../project.js";
|
|
18
18
|
import { Logger } from "../logger.js";
|
|
19
19
|
import { SiteEnv } from "../site-env.js";
|
|
20
20
|
const require = createRequire(import.meta.url);
|
|
@@ -65,8 +65,6 @@ export class App extends cdk.App {
|
|
|
65
65
|
/** @internal */
|
|
66
66
|
appPath;
|
|
67
67
|
/** @internal */
|
|
68
|
-
bootstrap;
|
|
69
|
-
/** @internal */
|
|
70
68
|
defaultFunctionProps;
|
|
71
69
|
_defaultRemovalPolicy;
|
|
72
70
|
/** @internal */
|
|
@@ -93,7 +91,6 @@ export class App extends cdk.App {
|
|
|
93
91
|
super(props);
|
|
94
92
|
AppContext.provide(this);
|
|
95
93
|
SiteEnv.reset();
|
|
96
|
-
this.bootstrap = deployProps.bootstrap;
|
|
97
94
|
this.appPath = process.cwd();
|
|
98
95
|
this.mode = deployProps.mode;
|
|
99
96
|
this.local = this.mode === "dev";
|
|
@@ -186,23 +183,6 @@ export class App extends cdk.App {
|
|
|
186
183
|
environment,
|
|
187
184
|
});
|
|
188
185
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Adds additional default config to be applied to all Lambda functions in the app.
|
|
191
|
-
*
|
|
192
|
-
* @deprecated The "addDefaultFunctionConfig" method will be removed in SST v2. Pass Parameters and Secrets in through the "addDefaultFunctionBinding" function. Read more about how to upgrade here — https://docs.serverless-stack.com/upgrade-guide#upgrade-to-v116
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```js
|
|
196
|
-
* // Change
|
|
197
|
-
* app.addDefaultFunctionConfig([STRIPE_KEY]);
|
|
198
|
-
*
|
|
199
|
-
* // To
|
|
200
|
-
* app.addDefaultFunctionBinding([STRIPE_KEY]);
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
addDefaultFunctionConfig(config) {
|
|
204
|
-
this.defaultFunctionProps.push({ config });
|
|
205
|
-
}
|
|
206
186
|
/**
|
|
207
187
|
* Binds additional default resources to be applied to all Lambda functions in the app.
|
|
208
188
|
*
|
|
@@ -226,7 +206,6 @@ export class App extends cdk.App {
|
|
|
226
206
|
Auth.injectConfig();
|
|
227
207
|
this.ensureUniqueConstructIds();
|
|
228
208
|
this.codegenTypes();
|
|
229
|
-
this.buildConstructsMetadata();
|
|
230
209
|
this.createBindingSsmParameters();
|
|
231
210
|
this.removeGovCloudUnsupportedResourceProperties();
|
|
232
211
|
for (const child of this.node.children) {
|
|
@@ -250,6 +229,7 @@ export class App extends cdk.App {
|
|
|
250
229
|
}
|
|
251
230
|
async finish() {
|
|
252
231
|
await useDeferredTasks().run();
|
|
232
|
+
this.buildConstructsMetadata();
|
|
253
233
|
}
|
|
254
234
|
isRunningSSTTest() {
|
|
255
235
|
// Check the env var set inside test/setup-tests.js
|
|
@@ -304,7 +284,14 @@ export class App extends cdk.App {
|
|
|
304
284
|
for (const child of this.node.children) {
|
|
305
285
|
if (child instanceof Stack) {
|
|
306
286
|
const stackName = child.node.id;
|
|
307
|
-
child.
|
|
287
|
+
child.addOutputs({
|
|
288
|
+
SSTMetadata: JSON.stringify({
|
|
289
|
+
app: this.name,
|
|
290
|
+
stage: this.stage,
|
|
291
|
+
version: useProject().version,
|
|
292
|
+
metadata: byStack[stackName] || [],
|
|
293
|
+
}),
|
|
294
|
+
});
|
|
308
295
|
}
|
|
309
296
|
}
|
|
310
297
|
}
|
|
@@ -452,7 +439,7 @@ export class App extends cdk.App {
|
|
|
452
439
|
fs.mkdirSync(typesPath, {
|
|
453
440
|
recursive: true,
|
|
454
441
|
});
|
|
455
|
-
fs.
|
|
442
|
+
fs.appendFileSync(`${typesPath}/index.ts`, [
|
|
456
443
|
`import "sst/node/config";`,
|
|
457
444
|
`declare module "sst/node/config" {`,
|
|
458
445
|
` export interface ConfigTypes {`,
|
|
@@ -476,7 +463,7 @@ export class App extends cdk.App {
|
|
|
476
463
|
const className = c.constructor.name;
|
|
477
464
|
const id = c.id;
|
|
478
465
|
// Case 1: variable does not have properties, ie. Secrets and Parameters
|
|
479
|
-
fs.
|
|
466
|
+
fs.appendFileSync(`${typesPath}/index.ts`, (binding.variables[0] === "."
|
|
480
467
|
? [
|
|
481
468
|
`import "sst/node/${binding.clientPackage}";`,
|
|
482
469
|
`declare module "sst/node/${binding.clientPackage}" {`,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export declare function weakImport(pkg: string): Promise<any>;
|
|
2
2
|
import { Construct } from "constructs";
|
|
3
3
|
import * as rds from "aws-cdk-lib/aws-rds";
|
|
4
|
-
import * as
|
|
5
|
-
import * as appsync from "@aws-cdk/aws-appsync-alpha";
|
|
4
|
+
import * as appsync from "aws-cdk-lib/aws-appsync";
|
|
6
5
|
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
|
|
7
6
|
import * as acm from "aws-cdk-lib/aws-certificatemanager";
|
|
8
7
|
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
|
|
@@ -178,7 +177,7 @@ export interface MappingTemplateInline {
|
|
|
178
177
|
*/
|
|
179
178
|
inline: string;
|
|
180
179
|
}
|
|
181
|
-
export
|
|
180
|
+
export type MappingTemplate = MappingTemplateFile | MappingTemplateInline;
|
|
182
181
|
/**
|
|
183
182
|
* Used to define full resolver config
|
|
184
183
|
*/
|
|
@@ -246,7 +245,7 @@ export interface AppSyncApiProps {
|
|
|
246
245
|
* });
|
|
247
246
|
* ```
|
|
248
247
|
*/
|
|
249
|
-
schema
|
|
248
|
+
schema?: string | string[];
|
|
250
249
|
/**
|
|
251
250
|
* Specify a custom domain to use in addition to the automatically generated one. SST currently supports domains that are configured using [Route 53](https://aws.amazon.com/route53/)
|
|
252
251
|
*
|
|
@@ -372,7 +371,7 @@ export declare class AppSyncApi extends Construct implements SSTConstruct {
|
|
|
372
371
|
};
|
|
373
372
|
private readonly props;
|
|
374
373
|
private _customDomainUrl?;
|
|
375
|
-
_cfnDomainName?:
|
|
374
|
+
_cfnDomainName?: appsync.CfnDomainName;
|
|
376
375
|
private readonly functionsByDsKey;
|
|
377
376
|
private readonly dataSourcesByDsKey;
|
|
378
377
|
private readonly dsKeysByResKey;
|
package/constructs/AppSyncApi.js
CHANGED
|
@@ -11,11 +11,11 @@ export async function weakImport(pkg) {
|
|
|
11
11
|
const { print, buildSchema } = await weakImport("graphql");
|
|
12
12
|
const { mergeTypeDefs } = await weakImport("@graphql-tools/merge");
|
|
13
13
|
import { Construct } from "constructs";
|
|
14
|
-
import * as appsync from "
|
|
14
|
+
import * as appsync from "aws-cdk-lib/aws-appsync";
|
|
15
15
|
import * as appSyncApiDomain from "./util/appSyncApiDomain.js";
|
|
16
16
|
import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
17
17
|
import { Function as Fn, } from "./Function.js";
|
|
18
|
-
import { useProject } from "../
|
|
18
|
+
import { useProject } from "../project.js";
|
|
19
19
|
/////////////////////
|
|
20
20
|
// Construct
|
|
21
21
|
/////////////////////
|
|
@@ -278,7 +278,10 @@ export class AppSyncApi extends Construct {
|
|
|
278
278
|
{});
|
|
279
279
|
// build schema
|
|
280
280
|
let mainSchema;
|
|
281
|
-
if (
|
|
281
|
+
if (!schema) {
|
|
282
|
+
throw new Error(`Missing "schema" in "${id}" AppSyncApi`);
|
|
283
|
+
}
|
|
284
|
+
else if (typeof schema === "string") {
|
|
282
285
|
mainSchema = appsync.SchemaFile.fromAsset(schema);
|
|
283
286
|
}
|
|
284
287
|
else {
|
|
@@ -314,8 +317,8 @@ export class AppSyncApi extends Construct {
|
|
|
314
317
|
if (domainData) {
|
|
315
318
|
this._cfnDomainName = this.cdk.graphqlApi.node.children.find((child) => child.cfnResourceType ===
|
|
316
319
|
"AWS::AppSync::DomainName");
|
|
317
|
-
const cfnDomainNameApiAssociation = this.cdk.graphqlApi.node.children.find((child) => child
|
|
318
|
-
|
|
320
|
+
const cfnDomainNameApiAssociation = this.cdk.graphqlApi.node.children.find((child) => child.cfnResourceType ===
|
|
321
|
+
"AWS::AppSync::DomainNameApiAssociation");
|
|
319
322
|
if (this._cfnDomainName && cfnDomainNameApiAssociation) {
|
|
320
323
|
cfnDomainNameApiAssociation.node.addDependency(this._cfnDomainName);
|
|
321
324
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Function as CdkFunction } from "aws-cdk-lib/aws-lambda";
|
|
2
2
|
import { SsrSite } from "./SsrSite.js";
|
|
3
3
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
4
4
|
/**
|
|
@@ -17,9 +17,8 @@ export declare class AstroSite extends SsrSite {
|
|
|
17
17
|
serverBuildOutputFile: string;
|
|
18
18
|
clientBuildOutputDir: string;
|
|
19
19
|
clientBuildVersionedSubDir: string;
|
|
20
|
-
siteStub: string;
|
|
21
20
|
};
|
|
22
21
|
protected validateBuildOutput(): void;
|
|
23
|
-
protected createFunctionForRegional():
|
|
22
|
+
protected createFunctionForRegional(): CdkFunction;
|
|
24
23
|
protected createFunctionForEdge(): EdgeFunction;
|
|
25
24
|
}
|
package/constructs/AstroSite.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import url from "url";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import
|
|
4
|
+
import { buildSync } from "esbuild";
|
|
5
|
+
import { Architecture } from "aws-cdk-lib/aws-lambda";
|
|
5
6
|
import { SsrSite } from "./SsrSite.js";
|
|
6
7
|
import { Function } from "./Function.js";
|
|
8
|
+
import { useProject } from "../project.js";
|
|
7
9
|
import { EdgeFunction } from "./EdgeFunction.js";
|
|
8
10
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
9
11
|
/**
|
|
@@ -23,7 +25,6 @@ export class AstroSite extends SsrSite {
|
|
|
23
25
|
serverBuildOutputFile: "dist/server/entry.mjs",
|
|
24
26
|
clientBuildOutputDir: "dist/client",
|
|
25
27
|
clientBuildVersionedSubDir: "assets",
|
|
26
|
-
siteStub: path.resolve(__dirname, "../support/astro-site-html-stub"),
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
validateBuildOutput() {
|
|
@@ -35,75 +36,64 @@ export class AstroSite extends SsrSite {
|
|
|
35
36
|
super.validateBuildOutput();
|
|
36
37
|
}
|
|
37
38
|
createFunctionForRegional() {
|
|
38
|
-
const {
|
|
39
|
-
// Bundle code
|
|
40
|
-
const handler = this.isPlaceholder
|
|
41
|
-
? path.resolve(__dirname, "../support/ssr-site-function-stub/index.handler")
|
|
42
|
-
: path.join(this.props.path, "dist", "server", "entry.handler");
|
|
39
|
+
const { memorySize, timeout, environment, bind, cdk } = this.props;
|
|
43
40
|
// Create function
|
|
44
41
|
const fn = new Function(this, `ServerFunction`, {
|
|
45
42
|
description: "Server handler",
|
|
46
|
-
handler,
|
|
43
|
+
handler: path.join(this.props.path, "dist", "server", "entry.handler"),
|
|
44
|
+
bind,
|
|
47
45
|
logRetention: "three_days",
|
|
48
46
|
runtime: "nodejs16.x",
|
|
49
|
-
memorySize
|
|
50
|
-
timeout
|
|
47
|
+
memorySize,
|
|
48
|
+
timeout,
|
|
51
49
|
nodejs: {
|
|
52
50
|
format: "esm",
|
|
53
51
|
},
|
|
54
|
-
enableLiveDev: false,
|
|
55
52
|
environment,
|
|
53
|
+
...cdk?.server,
|
|
54
|
+
architecture: cdk?.server?.architecture === Architecture.ARM_64 ? "arm_64" : "x86_64",
|
|
56
55
|
});
|
|
57
56
|
fn._disableBind = true;
|
|
58
57
|
return fn;
|
|
59
58
|
}
|
|
60
59
|
createFunctionForEdge() {
|
|
61
|
-
const {
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
].join(""),
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
if (result.errors.length > 0) {
|
|
91
|
-
result.errors.forEach((error) => console.error(error));
|
|
92
|
-
throw new Error(`There was a problem bundling the function code for the ${this.id} AstroSite.`);
|
|
93
|
-
}
|
|
94
|
-
// Create package.json
|
|
95
|
-
fs.writeFileSync(path.join(outputPath, "package.json"), `{"type":"module"}`);
|
|
96
|
-
bundlePath = outputPath;
|
|
97
|
-
handler = "entry.handler";
|
|
60
|
+
const { timeout, memorySize, permissions, environment } = this.props;
|
|
61
|
+
// Create a directory that we will use to create the bundled version
|
|
62
|
+
// of the "core server build" along with our custom Lamba server handler.
|
|
63
|
+
const outputPath = path.resolve(path.join(useProject().paths.artifacts, `AstroSiteFunction-${this.node.id}-${this.node.addr}`));
|
|
64
|
+
const result = buildSync({
|
|
65
|
+
entryPoints: [
|
|
66
|
+
path.join(this.props.path, this.buildConfig.serverBuildOutputFile),
|
|
67
|
+
],
|
|
68
|
+
target: "esnext",
|
|
69
|
+
format: "esm",
|
|
70
|
+
platform: "node",
|
|
71
|
+
metafile: true,
|
|
72
|
+
bundle: true,
|
|
73
|
+
write: true,
|
|
74
|
+
allowOverwrite: true,
|
|
75
|
+
outfile: path.join(outputPath, "entry.mjs"),
|
|
76
|
+
banner: {
|
|
77
|
+
js: [
|
|
78
|
+
`import { createRequire as topLevelCreateRequire } from 'module';`,
|
|
79
|
+
`const require = topLevelCreateRequire(import.meta.url);`,
|
|
80
|
+
].join(""),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
if (result.errors.length > 0) {
|
|
84
|
+
result.errors.forEach((error) => console.error(error));
|
|
85
|
+
throw new Error(`There was a problem bundling the function code for the ${this.id} AstroSite.`);
|
|
98
86
|
}
|
|
87
|
+
// Create package.json
|
|
88
|
+
fs.writeFileSync(path.join(outputPath, "package.json"), `{"type":"module"}`);
|
|
99
89
|
// Create function
|
|
100
90
|
return new EdgeFunction(this, `Server`, {
|
|
101
91
|
scopeOverride: this,
|
|
102
|
-
bundlePath,
|
|
103
|
-
handler,
|
|
104
|
-
timeout
|
|
105
|
-
|
|
106
|
-
permissions
|
|
92
|
+
bundlePath: outputPath,
|
|
93
|
+
handler: "entry.handler",
|
|
94
|
+
timeout,
|
|
95
|
+
memorySize,
|
|
96
|
+
permissions,
|
|
107
97
|
environment,
|
|
108
98
|
format: "esm",
|
|
109
99
|
});
|
package/constructs/Auth.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as ssm from "aws-cdk-lib/aws-ssm";
|
|
|
2
2
|
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
3
3
|
import { Construct } from "constructs";
|
|
4
4
|
import { Stack } from "./Stack.js";
|
|
5
|
-
import { ENVIRONMENT_PLACEHOLDER, getEnvironmentKey, getParameterPath } from "./util/functionBinding.js";
|
|
5
|
+
import { ENVIRONMENT_PLACEHOLDER, getEnvironmentKey, getParameterPath, } from "./util/functionBinding.js";
|
|
6
6
|
import { CustomResource } from "aws-cdk-lib";
|
|
7
7
|
const PUBLIC_KEY_PROP = "publicKey";
|
|
8
8
|
const PRIVATE_KEY_PROP = "privateKey";
|
|
@@ -42,15 +42,25 @@ export class Auth extends Construct {
|
|
|
42
42
|
resourceType: "Custom::AuthKeys",
|
|
43
43
|
properties: {
|
|
44
44
|
publicPath: getParameterPath(this, PUBLIC_KEY_PROP),
|
|
45
|
-
privatePath: getParameterPath(this, PRIVATE_KEY_PROP)
|
|
46
|
-
}
|
|
45
|
+
privatePath: getParameterPath(this, PRIVATE_KEY_PROP),
|
|
46
|
+
},
|
|
47
47
|
});
|
|
48
|
+
stack.customResourceHandler.role?.addToPrincipalPolicy(new PolicyStatement({
|
|
49
|
+
actions: [
|
|
50
|
+
"ssm:GetParameter",
|
|
51
|
+
"ssm:PutParameter",
|
|
52
|
+
"ssm:DeleteParameter",
|
|
53
|
+
],
|
|
54
|
+
resources: [
|
|
55
|
+
`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter/*`,
|
|
56
|
+
],
|
|
57
|
+
}));
|
|
48
58
|
}
|
|
49
59
|
/** @internal */
|
|
50
60
|
getConstructMetadata() {
|
|
51
61
|
return {
|
|
52
62
|
type: "Auth",
|
|
53
|
-
data: {}
|
|
63
|
+
data: {},
|
|
54
64
|
};
|
|
55
65
|
}
|
|
56
66
|
/** @internal */
|
|
@@ -62,14 +72,14 @@ export class Auth extends Construct {
|
|
|
62
72
|
publicKey: {
|
|
63
73
|
environment: ENVIRONMENT_PLACEHOLDER,
|
|
64
74
|
// SSM parameters will be created by the custom resource
|
|
65
|
-
parameter: undefined
|
|
66
|
-
}
|
|
75
|
+
parameter: undefined,
|
|
76
|
+
},
|
|
67
77
|
},
|
|
68
78
|
permissions: {
|
|
69
79
|
"ssm:GetParameters": [
|
|
70
|
-
`arn:
|
|
71
|
-
]
|
|
72
|
-
}
|
|
80
|
+
`arn:${Stack.of(this).partition}:ssm:${app.region}:${app.account}:parameter${getParameterPath(this, PUBLIC_KEY_PROP)}`,
|
|
81
|
+
],
|
|
82
|
+
},
|
|
73
83
|
};
|
|
74
84
|
}
|
|
75
85
|
/**
|
|
@@ -93,7 +103,7 @@ export class Auth extends Construct {
|
|
|
93
103
|
throw new Error("This Auth construct has already been attached to this Api construct.");
|
|
94
104
|
}
|
|
95
105
|
// Validate: one Api can only have one Auth attached to it
|
|
96
|
-
if (Array.from(Auth.list).some(auth => auth.apis.has(props.api))) {
|
|
106
|
+
if (Array.from(Auth.list).some((auth) => auth.apis.has(props.api))) {
|
|
97
107
|
throw new Error("This Api construct already has an Auth construct attached.");
|
|
98
108
|
}
|
|
99
109
|
const prefix = props.prefix || "/auth";
|
|
@@ -101,8 +111,9 @@ export class Auth extends Construct {
|
|
|
101
111
|
props.api.addRoutes(scope, {
|
|
102
112
|
[path]: {
|
|
103
113
|
type: "function",
|
|
104
|
-
function: this.authenticator
|
|
105
|
-
|
|
114
|
+
function: this.authenticator,
|
|
115
|
+
authorizer: "none",
|
|
116
|
+
},
|
|
106
117
|
});
|
|
107
118
|
// Auth construct has two types of Function bindinds:
|
|
108
119
|
// - Api routes: bindings defined in `getFunctionBinding()`
|
|
@@ -117,9 +128,9 @@ export class Auth extends Construct {
|
|
|
117
128
|
actions: ["ssm:GetParameters"],
|
|
118
129
|
effect: Effect.ALLOW,
|
|
119
130
|
resources: [
|
|
120
|
-
`arn:
|
|
121
|
-
]
|
|
122
|
-
})
|
|
131
|
+
`arn:${Stack.of(this).partition}:ssm:${app.region}:${app.account}:parameter${getParameterPath(this, "*")}`,
|
|
132
|
+
],
|
|
133
|
+
}),
|
|
123
134
|
]);
|
|
124
135
|
}
|
|
125
136
|
// Create a parameter for prefix
|
|
@@ -128,7 +139,7 @@ export class Auth extends Construct {
|
|
|
128
139
|
if (this.apis.size === 0) {
|
|
129
140
|
new ssm.StringParameter(this, "prefix", {
|
|
130
141
|
parameterName: getParameterPath(this, PREFIX_PROP),
|
|
131
|
-
stringValue: prefix
|
|
142
|
+
stringValue: prefix,
|
|
132
143
|
});
|
|
133
144
|
}
|
|
134
145
|
this.apis.add(props.api);
|