sst 2.26.2 → 2.26.4
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/cli/commands/types.js +3 -7
- package/constructs/Api.js +2 -0
- package/constructs/ApiGatewayV1Api.js +2 -0
- package/constructs/App.d.ts +3 -1
- package/constructs/App.js +63 -62
- package/constructs/AppSyncApi.js +2 -0
- package/constructs/AstroSite.d.ts +50 -11
- package/constructs/AstroSite.js +69 -51
- package/constructs/Auth.js +2 -0
- package/constructs/Bucket.js +2 -0
- package/constructs/Cognito.js +2 -0
- package/constructs/Cron.js +2 -0
- package/constructs/EdgeFunction.d.ts +3 -4
- package/constructs/EdgeFunction.js +13 -9
- package/constructs/EventBus.js +2 -0
- package/constructs/Function.d.ts +5 -1
- package/constructs/Function.js +8 -6
- package/constructs/Job.js +3 -3
- package/constructs/KinesisStream.js +2 -0
- package/constructs/NextjsSite.d.ts +84 -22
- package/constructs/NextjsSite.js +150 -254
- package/constructs/Parameter.js +2 -0
- package/constructs/Queue.js +2 -0
- package/constructs/RDS.js +5 -4
- package/constructs/RemixSite.d.ts +65 -11
- package/constructs/RemixSite.js +112 -71
- package/constructs/Script.js +2 -0
- package/constructs/Secret.js +2 -0
- package/constructs/Service.js +4 -3
- package/constructs/SolidStartSite.d.ts +48 -9
- package/constructs/SolidStartSite.js +68 -40
- package/constructs/SsrFunction.d.ts +4 -5
- package/constructs/SsrFunction.js +18 -13
- package/constructs/SsrSite.d.ts +74 -68
- package/constructs/SsrSite.js +657 -682
- package/constructs/StaticSite.js +2 -0
- package/constructs/SvelteKitSite.d.ts +80 -12
- package/constructs/SvelteKitSite.js +90 -64
- package/constructs/Table.js +2 -0
- package/constructs/Topic.js +2 -0
- package/constructs/WebSocketApi.js +2 -0
- package/constructs/deprecated/NextjsSite.js +1 -0
- package/constructs/future/Auth.js +1 -0
- package/package.json +1 -1
- package/support/remix-site-function/edge-server.js +2 -4
- package/support/remix-site-function/regional-server.js +2 -4
package/cli/commands/types.js
CHANGED
|
@@ -8,14 +8,10 @@ export const types = (program) => program.command("types", "Generate resource ty
|
|
|
8
8
|
try {
|
|
9
9
|
const project = useProject();
|
|
10
10
|
const [_metafile, sstConfig] = await Stacks.load(project.paths.config);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name: project.config.name,
|
|
15
|
-
region: project.config.region,
|
|
11
|
+
await Stacks.synth({
|
|
12
|
+
fn: sstConfig.stacks,
|
|
13
|
+
mode: "remove",
|
|
16
14
|
});
|
|
17
|
-
sstConfig.stacks(app);
|
|
18
|
-
app.codegenTypes();
|
|
19
15
|
Colors.line(Colors.success(`✔ `), `Types generated in ${path.resolve(project.paths.out, "types")}`);
|
|
20
16
|
await exit();
|
|
21
17
|
}
|
package/constructs/Api.js
CHANGED
|
@@ -54,6 +54,8 @@ export class Api extends Construct {
|
|
|
54
54
|
this.createHttpApi();
|
|
55
55
|
this.addAuthorizers(this.props.authorizers || {});
|
|
56
56
|
this.addRoutes(this, this.props.routes || {});
|
|
57
|
+
const app = this.node.root;
|
|
58
|
+
app.registerTypes(this);
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* The AWS generated URL of the Api.
|
|
@@ -63,6 +63,8 @@ export class ApiGatewayV1Api extends Construct {
|
|
|
63
63
|
this.createRestApi();
|
|
64
64
|
this.addAuthorizers(this.props.authorizers || {});
|
|
65
65
|
this.addRoutes(this, this.props.routes || {});
|
|
66
|
+
const app = this.node.root;
|
|
67
|
+
app.registerTypes(this);
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* The AWS generated URL of the Api.
|
package/constructs/App.d.ts
CHANGED
|
@@ -149,6 +149,9 @@ export declare class App extends CDKApp {
|
|
|
149
149
|
* Adds additional default layers to be applied to all Lambda functions in the stack.
|
|
150
150
|
*/
|
|
151
151
|
addDefaultFunctionLayers(layers: ILayerVersion[]): void;
|
|
152
|
+
private useTypesPath;
|
|
153
|
+
private createTypesFile;
|
|
154
|
+
registerTypes(c: SSTConstruct): void;
|
|
152
155
|
private isFinished;
|
|
153
156
|
finish(): Promise<void>;
|
|
154
157
|
isRunningSSTTest(): boolean;
|
|
@@ -159,7 +162,6 @@ export declare class App extends CDKApp {
|
|
|
159
162
|
private applyRemovalPolicy;
|
|
160
163
|
private removeGovCloudUnsupportedResourceProperties;
|
|
161
164
|
private ensureUniqueConstructIds;
|
|
162
|
-
codegenTypes(): void;
|
|
163
165
|
private foreachConstruct;
|
|
164
166
|
stack<T extends FunctionalStack<any>>(fn: T, props?: StackProps & {
|
|
165
167
|
id?: string;
|
package/constructs/App.js
CHANGED
|
@@ -78,6 +78,7 @@ export class App extends CDKApp {
|
|
|
78
78
|
deployProps.account || process.env.CDK_DEFAULT_ACCOUNT || "my-account";
|
|
79
79
|
this.isActiveStack = deployProps.isActiveStack;
|
|
80
80
|
this.defaultFunctionProps = [];
|
|
81
|
+
this.createTypesFile();
|
|
81
82
|
if (this.mode === "dev") {
|
|
82
83
|
this.debugScriptVersion = deployProps.debugScriptVersion;
|
|
83
84
|
this.debugIncreaseTimeout = deployProps.debugIncreaseTimeout;
|
|
@@ -171,6 +172,68 @@ export class App extends CDKApp {
|
|
|
171
172
|
layers,
|
|
172
173
|
});
|
|
173
174
|
}
|
|
175
|
+
useTypesPath() {
|
|
176
|
+
const project = useProject();
|
|
177
|
+
return path.resolve(project.paths.out, "types");
|
|
178
|
+
}
|
|
179
|
+
createTypesFile() {
|
|
180
|
+
const typesPath = this.useTypesPath();
|
|
181
|
+
Logger.debug(`Generating types in ${typesPath}`);
|
|
182
|
+
fs.rmSync(typesPath, {
|
|
183
|
+
recursive: true,
|
|
184
|
+
force: true,
|
|
185
|
+
});
|
|
186
|
+
fs.mkdirSync(typesPath, {
|
|
187
|
+
recursive: true,
|
|
188
|
+
});
|
|
189
|
+
fs.appendFileSync(`${typesPath}/index.ts`, [
|
|
190
|
+
`import "sst/node/config";`,
|
|
191
|
+
`declare module "sst/node/config" {`,
|
|
192
|
+
` export interface ConfigTypes {`,
|
|
193
|
+
` APP: string;`,
|
|
194
|
+
` STAGE: string;`,
|
|
195
|
+
` }`,
|
|
196
|
+
`}`,
|
|
197
|
+
``,
|
|
198
|
+
``,
|
|
199
|
+
].join("\n"));
|
|
200
|
+
}
|
|
201
|
+
registerTypes(c) {
|
|
202
|
+
const typesPath = this.useTypesPath();
|
|
203
|
+
if ("_doNotAllowOthersToBind" in c && c._doNotAllowOthersToBind) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const binding = bindType(c);
|
|
207
|
+
if (!binding) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const className = c.constructor.name;
|
|
211
|
+
const id = c.id;
|
|
212
|
+
fs.appendFileSync(`${typesPath}/index.ts`, (binding.variables[0] === "."
|
|
213
|
+
? // Case: variable does not have properties, ie. Secrets and Parameters
|
|
214
|
+
[
|
|
215
|
+
`import "sst/node/${binding.clientPackage}";`,
|
|
216
|
+
`declare module "sst/node/${binding.clientPackage}" {`,
|
|
217
|
+
` export interface ${className}Resources {`,
|
|
218
|
+
` "${id}": string;`,
|
|
219
|
+
` }`,
|
|
220
|
+
`}`,
|
|
221
|
+
``,
|
|
222
|
+
``,
|
|
223
|
+
]
|
|
224
|
+
: [
|
|
225
|
+
`import "sst/node/${binding.clientPackage}";`,
|
|
226
|
+
`declare module "sst/node/${binding.clientPackage}" {`,
|
|
227
|
+
` export interface ${className}Resources {`,
|
|
228
|
+
` "${id}": {`,
|
|
229
|
+
...binding.variables.map((p) => ` ${p}: string;`),
|
|
230
|
+
` }`,
|
|
231
|
+
` }`,
|
|
232
|
+
`}`,
|
|
233
|
+
``,
|
|
234
|
+
``,
|
|
235
|
+
]).join("\n"));
|
|
236
|
+
}
|
|
174
237
|
isFinished = false;
|
|
175
238
|
async finish() {
|
|
176
239
|
if (this.isFinished)
|
|
@@ -180,7 +243,6 @@ export class App extends CDKApp {
|
|
|
180
243
|
Auth.injectConfig();
|
|
181
244
|
this.buildConstructsMetadata();
|
|
182
245
|
this.ensureUniqueConstructIds();
|
|
183
|
-
this.codegenTypes();
|
|
184
246
|
// Run deferred tasks
|
|
185
247
|
// - after codegen b/c some frontend frameworks (ie. Next.js apps) runs
|
|
186
248
|
// type checking in the build step
|
|
@@ -410,67 +472,6 @@ export class App extends CDKApp {
|
|
|
410
472
|
}
|
|
411
473
|
Aspects.of(this).add(new EnsureUniqueConstructIds());
|
|
412
474
|
}
|
|
413
|
-
codegenTypes() {
|
|
414
|
-
const project = useProject();
|
|
415
|
-
const typesPath = path.resolve(project.paths.out, "types");
|
|
416
|
-
Logger.debug(`Generating types in ${typesPath}`);
|
|
417
|
-
fs.rmSync(typesPath, {
|
|
418
|
-
recursive: true,
|
|
419
|
-
force: true,
|
|
420
|
-
});
|
|
421
|
-
fs.mkdirSync(typesPath, {
|
|
422
|
-
recursive: true,
|
|
423
|
-
});
|
|
424
|
-
fs.appendFileSync(`${typesPath}/index.ts`, [
|
|
425
|
-
`import "sst/node/config";`,
|
|
426
|
-
`declare module "sst/node/config" {`,
|
|
427
|
-
` export interface ConfigTypes {`,
|
|
428
|
-
` APP: string;`,
|
|
429
|
-
` STAGE: string;`,
|
|
430
|
-
` }`,
|
|
431
|
-
`}`,
|
|
432
|
-
``,
|
|
433
|
-
``,
|
|
434
|
-
].join("\n"));
|
|
435
|
-
this.foreachConstruct((c) => {
|
|
436
|
-
if (!isSSTConstruct(c)) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if ("_doNotAllowOthersToBind" in c && c._doNotAllowOthersToBind) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
const binding = bindType(c);
|
|
443
|
-
if (!binding) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const className = c.constructor.name;
|
|
447
|
-
const id = c.id;
|
|
448
|
-
// Case 1: variable does not have properties, ie. Secrets and Parameters
|
|
449
|
-
fs.appendFileSync(`${typesPath}/index.ts`, (binding.variables[0] === "."
|
|
450
|
-
? [
|
|
451
|
-
`import "sst/node/${binding.clientPackage}";`,
|
|
452
|
-
`declare module "sst/node/${binding.clientPackage}" {`,
|
|
453
|
-
` export interface ${className}Resources {`,
|
|
454
|
-
` "${id}": string;`,
|
|
455
|
-
` }`,
|
|
456
|
-
`}`,
|
|
457
|
-
``,
|
|
458
|
-
``,
|
|
459
|
-
]
|
|
460
|
-
: [
|
|
461
|
-
`import "sst/node/${binding.clientPackage}";`,
|
|
462
|
-
`declare module "sst/node/${binding.clientPackage}" {`,
|
|
463
|
-
` export interface ${className}Resources {`,
|
|
464
|
-
` "${id}": {`,
|
|
465
|
-
...binding.variables.map((p) => ` ${p}: string;`),
|
|
466
|
-
` }`,
|
|
467
|
-
` }`,
|
|
468
|
-
`}`,
|
|
469
|
-
``,
|
|
470
|
-
``,
|
|
471
|
-
]).join("\n"));
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
475
|
foreachConstruct(fn) {
|
|
475
476
|
const loop = (parent) => {
|
|
476
477
|
for (const child of parent.node.children) {
|
package/constructs/AppSyncApi.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { SsrSite } from "./SsrSite.js";
|
|
2
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
3
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
4
2
|
/**
|
|
5
3
|
* The `AstroSite` construct is a higher level CDK construct that makes it easy to create a Astro app.
|
|
6
4
|
* @example
|
|
@@ -13,15 +11,57 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
13
11
|
* ```
|
|
14
12
|
*/
|
|
15
13
|
export declare class AstroSite extends SsrSite {
|
|
16
|
-
protected
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
protected typesPath: string;
|
|
15
|
+
protected plan(): {
|
|
16
|
+
cloudFrontFunctions?: {
|
|
17
|
+
serverCfFunction: {
|
|
18
|
+
constructId: string;
|
|
19
|
+
injections: string[];
|
|
20
|
+
};
|
|
21
|
+
} | undefined;
|
|
22
|
+
edgeFunctions?: {
|
|
23
|
+
edgeServer: {
|
|
24
|
+
constructId: string;
|
|
25
|
+
function: {
|
|
26
|
+
description: string;
|
|
27
|
+
handler: string;
|
|
28
|
+
scopeOverride: AstroSite;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
} | undefined;
|
|
32
|
+
origins: {
|
|
33
|
+
s3: {
|
|
34
|
+
type: "s3";
|
|
35
|
+
copy: {
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
cached: true;
|
|
39
|
+
versionedSubDir: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
regionalServer?: {
|
|
43
|
+
type: "function";
|
|
44
|
+
constructId: string;
|
|
45
|
+
function: {
|
|
46
|
+
description: string;
|
|
47
|
+
handler: string;
|
|
48
|
+
};
|
|
49
|
+
streaming: true;
|
|
50
|
+
} | undefined;
|
|
51
|
+
};
|
|
52
|
+
behaviors: {
|
|
53
|
+
cacheType: "server" | "static";
|
|
54
|
+
pattern?: string | undefined;
|
|
55
|
+
origin: "s3" | "regionalServer";
|
|
56
|
+
cfFunction?: "serverCfFunction" | undefined;
|
|
57
|
+
edgeFunction?: "edgeServer" | undefined;
|
|
58
|
+
}[];
|
|
59
|
+
cachePolicyAllowedHeaders?: string[] | undefined;
|
|
60
|
+
buildId?: string | undefined;
|
|
61
|
+
warmerConfig?: {
|
|
62
|
+
function: string;
|
|
63
|
+
} | undefined;
|
|
21
64
|
};
|
|
22
|
-
protected validateBuildOutput(): void;
|
|
23
|
-
protected createFunctionForRegional(): SsrFunction;
|
|
24
|
-
protected createFunctionForEdge(): EdgeFunction;
|
|
25
65
|
getConstructMetadata(): {
|
|
26
66
|
data: {
|
|
27
67
|
mode: "placeholder" | "deployed";
|
|
@@ -35,5 +75,4 @@ export declare class AstroSite extends SsrSite {
|
|
|
35
75
|
};
|
|
36
76
|
type: "AstroSite";
|
|
37
77
|
};
|
|
38
|
-
protected supportsStreaming(): boolean;
|
|
39
78
|
}
|
package/constructs/AstroSite.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { SsrSite } from "./SsrSite.js";
|
|
4
|
-
import { SsrFunction } from "./SsrFunction.js";
|
|
5
|
-
import { EdgeFunction } from "./EdgeFunction.js";
|
|
6
4
|
/**
|
|
7
5
|
* The `AstroSite` construct is a higher level CDK construct that makes it easy to create a Astro app.
|
|
8
6
|
* @example
|
|
@@ -15,55 +13,78 @@ import { EdgeFunction } from "./EdgeFunction.js";
|
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
17
15
|
export class AstroSite extends SsrSite {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clientBuildOutputDir: "dist/client",
|
|
23
|
-
clientBuildVersionedSubDir: "assets",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
validateBuildOutput() {
|
|
27
|
-
const serverDir = path.join(this.props.path, "dist/server");
|
|
28
|
-
const clientDir = path.join(this.props.path, "dist/client");
|
|
29
|
-
if (!fs.existsSync(serverDir) || !fs.existsSync(clientDir)) {
|
|
30
|
-
throw new Error(`Build output inside "dist/" does not contain the "server" and "client" folders. Make sure Server-side Rendering (SSR) is enabled in your Astro app. If you are looking to deploy the Astro app as a static site, please use the StaticSite construct — https://docs.sst.dev/constructs/StaticSite`);
|
|
31
|
-
}
|
|
32
|
-
super.validateBuildOutput();
|
|
33
|
-
}
|
|
34
|
-
createFunctionForRegional() {
|
|
35
|
-
const { runtime, timeout, memorySize, permissions, environment, nodejs, bind, cdk, } = this.props;
|
|
36
|
-
return new SsrFunction(this, `ServerFunction`, {
|
|
16
|
+
typesPath = "src";
|
|
17
|
+
plan() {
|
|
18
|
+
const { path: sitePath, edge } = this.props;
|
|
19
|
+
const serverConfig = {
|
|
37
20
|
description: "Server handler for Astro",
|
|
38
|
-
handler: path.join(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
21
|
+
handler: path.join(sitePath, "dist", "server", "entry.handler"),
|
|
22
|
+
};
|
|
23
|
+
return this.validatePlan({
|
|
24
|
+
cloudFrontFunctions: {
|
|
25
|
+
serverCfFunction: {
|
|
26
|
+
constructId: "CloudFrontFunction",
|
|
27
|
+
injections: [this.useCloudFrontFunctionHostHeaderInjection()],
|
|
28
|
+
},
|
|
45
29
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
30
|
+
edgeFunctions: edge
|
|
31
|
+
? {
|
|
32
|
+
edgeServer: {
|
|
33
|
+
constructId: "Server",
|
|
34
|
+
function: {
|
|
35
|
+
scopeOverride: this,
|
|
36
|
+
...serverConfig,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
: undefined,
|
|
41
|
+
origins: {
|
|
42
|
+
...(edge
|
|
43
|
+
? {}
|
|
44
|
+
: {
|
|
45
|
+
regionalServer: {
|
|
46
|
+
type: "function",
|
|
47
|
+
constructId: "ServerFunction",
|
|
48
|
+
function: serverConfig,
|
|
49
|
+
streaming: true,
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
s3: {
|
|
53
|
+
type: "s3",
|
|
54
|
+
copy: [
|
|
55
|
+
{
|
|
56
|
+
from: "dist/client",
|
|
57
|
+
to: "",
|
|
58
|
+
cached: true,
|
|
59
|
+
versionedSubDir: "assets",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
66
63
|
},
|
|
64
|
+
behaviors: [
|
|
65
|
+
edge
|
|
66
|
+
? {
|
|
67
|
+
cacheType: "server",
|
|
68
|
+
cfFunction: "serverCfFunction",
|
|
69
|
+
edgeFunction: "edgeServer",
|
|
70
|
+
origin: "s3",
|
|
71
|
+
}
|
|
72
|
+
: {
|
|
73
|
+
cacheType: "server",
|
|
74
|
+
cfFunction: "serverCfFunction",
|
|
75
|
+
origin: "regionalServer",
|
|
76
|
+
},
|
|
77
|
+
// create 1 behaviour for each top level asset file/folder
|
|
78
|
+
...fs.readdirSync(path.join(sitePath, "dist/client")).map((item) => ({
|
|
79
|
+
cacheType: "static",
|
|
80
|
+
pattern: fs
|
|
81
|
+
.statSync(path.join(sitePath, "dist/client", item))
|
|
82
|
+
.isDirectory()
|
|
83
|
+
? `${item}/*`
|
|
84
|
+
: item,
|
|
85
|
+
origin: "s3",
|
|
86
|
+
})),
|
|
87
|
+
],
|
|
67
88
|
});
|
|
68
89
|
}
|
|
69
90
|
getConstructMetadata() {
|
|
@@ -72,7 +93,4 @@ export class AstroSite extends SsrSite {
|
|
|
72
93
|
...this.getConstructMetadataBase(),
|
|
73
94
|
};
|
|
74
95
|
}
|
|
75
|
-
supportsStreaming() {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
96
|
}
|
package/constructs/Auth.js
CHANGED
package/constructs/Bucket.js
CHANGED
|
@@ -34,6 +34,8 @@ export class Bucket extends Construct {
|
|
|
34
34
|
this.cdk = {};
|
|
35
35
|
this.createBucket();
|
|
36
36
|
this.addNotifications(this, props?.notifications || {});
|
|
37
|
+
const app = this.node.root;
|
|
38
|
+
app.registerTypes(this);
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* The ARN of the internally created `Bucket` instance.
|
package/constructs/Cognito.js
CHANGED
package/constructs/Cron.js
CHANGED
|
@@ -9,9 +9,9 @@ import { Permissions } from "./util/permission.js";
|
|
|
9
9
|
export interface EdgeFunctionProps {
|
|
10
10
|
bundle?: string;
|
|
11
11
|
handler: string;
|
|
12
|
-
runtime
|
|
13
|
-
timeout
|
|
14
|
-
memorySize
|
|
12
|
+
runtime?: "nodejs14.x" | "nodejs16.x" | "nodejs18.x";
|
|
13
|
+
timeout?: number | Duration;
|
|
14
|
+
memorySize?: number | Size;
|
|
15
15
|
permissions?: Permissions;
|
|
16
16
|
environment?: Record<string, string>;
|
|
17
17
|
bind?: SSTConstruct[];
|
|
@@ -30,7 +30,6 @@ export declare class EdgeFunction extends Construct {
|
|
|
30
30
|
private bindingEnvs;
|
|
31
31
|
private props;
|
|
32
32
|
constructor(scope: Construct, id: string, props: EdgeFunctionProps);
|
|
33
|
-
build(): Promise<void>;
|
|
34
33
|
attachPermissions(permissions: Permissions): void;
|
|
35
34
|
addEnvironment(key: string, value: string): void;
|
|
36
35
|
private buildAssetFromHandler;
|
|
@@ -16,6 +16,7 @@ import { bindEnvironment, bindPermissions, getReferencedSecrets, } from "./util/
|
|
|
16
16
|
import { toCdkSize } from "./util/size.js";
|
|
17
17
|
import { toCdkDuration } from "./util/duration.js";
|
|
18
18
|
import { attachPermissionsToRole } from "./util/permission.js";
|
|
19
|
+
import { useDeferredTasks } from "./deferred_task.js";
|
|
19
20
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
20
21
|
/////////////////////
|
|
21
22
|
// Construct
|
|
@@ -42,10 +43,13 @@ export class EdgeFunction extends Construct {
|
|
|
42
43
|
this.scope = props.scopeOverride || this;
|
|
43
44
|
this.props = {
|
|
44
45
|
...props,
|
|
46
|
+
runtime: "nodejs18.x",
|
|
47
|
+
timeout: 10,
|
|
48
|
+
memorySize: 1024,
|
|
45
49
|
environment: props.environment || {},
|
|
46
50
|
permissions: props.permissions || [],
|
|
47
51
|
};
|
|
48
|
-
// Bind first b/
|
|
52
|
+
// Bind first b/c function's environment variables cannot be added after
|
|
49
53
|
this.bindingEnvs = {};
|
|
50
54
|
this.bind(props.bind || []);
|
|
51
55
|
// Create function with placeholder code
|
|
@@ -67,14 +71,14 @@ export class EdgeFunction extends Construct {
|
|
|
67
71
|
this.currentVersion = Version.fromVersionArn(this, `${id}FunctionVersion`, `${fnArn}:${versionId}`);
|
|
68
72
|
this.assetReplacer = assetReplacer;
|
|
69
73
|
this.assetReplacerPolicy = assetReplacerPolicy;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
useDeferredTasks().add(async () => {
|
|
75
|
+
const { bundle, handler } = props;
|
|
76
|
+
const { asset, handlerFilename } = bundle
|
|
77
|
+
? await this.buildAssetFromBundle(bundle, handler)
|
|
78
|
+
: await this.buildAssetFromHandler();
|
|
79
|
+
this.updateCodeReplacer(asset.s3BucketName, asset.s3ObjectKey, handlerFilename);
|
|
80
|
+
this.updateFunctionInUsEast1(asset.s3BucketName, asset.s3ObjectKey);
|
|
81
|
+
});
|
|
78
82
|
}
|
|
79
83
|
attachPermissions(permissions) {
|
|
80
84
|
attachPermissionsToRole(this.role, permissions);
|
package/constructs/EventBus.js
CHANGED
|
@@ -53,6 +53,8 @@ export class EventBus extends Construct {
|
|
|
53
53
|
this.cdk = {};
|
|
54
54
|
this.createEventBus();
|
|
55
55
|
this.addRules(this, props?.rules || {});
|
|
56
|
+
const app = this.node.root;
|
|
57
|
+
app.registerTypes(this);
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* The ARN of the internally created `EventBus` instance.
|
package/constructs/Function.d.ts
CHANGED
|
@@ -296,6 +296,10 @@ export interface FunctionProps extends Omit<FunctionOptions, "functionName" | "m
|
|
|
296
296
|
* ```
|
|
297
297
|
*/
|
|
298
298
|
logRetention?: Lowercase<keyof typeof RetentionDays>;
|
|
299
|
+
/**
|
|
300
|
+
* @internal
|
|
301
|
+
*/
|
|
302
|
+
_doNotAllowOthersToBind?: boolean;
|
|
299
303
|
}
|
|
300
304
|
export interface FunctionNameProps {
|
|
301
305
|
/**
|
|
@@ -617,7 +621,7 @@ export declare class Function extends CDKFunction implements SSTConstruct {
|
|
|
617
621
|
readonly id: string;
|
|
618
622
|
readonly _isLiveDevEnabled: boolean;
|
|
619
623
|
/** @internal */
|
|
620
|
-
_doNotAllowOthersToBind?: boolean;
|
|
624
|
+
readonly _doNotAllowOthersToBind?: boolean;
|
|
621
625
|
private functionUrl?;
|
|
622
626
|
private props;
|
|
623
627
|
private allBindings;
|
package/constructs/Function.js
CHANGED
|
@@ -285,6 +285,7 @@ export class Function extends CDKFunction {
|
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
this.id = id;
|
|
288
|
+
this._doNotAllowOthersToBind = props._doNotAllowOthersToBind;
|
|
288
289
|
this.props = props || {};
|
|
289
290
|
if (this.isNodeRuntime()) {
|
|
290
291
|
// Enable reusing connections with Keep-Alive for NodeJs
|
|
@@ -305,6 +306,7 @@ export class Function extends CDKFunction {
|
|
|
305
306
|
this.createUrl();
|
|
306
307
|
this._isLiveDevEnabled = isLiveDevEnabled;
|
|
307
308
|
useFunctions().add(this.node.addr, props);
|
|
309
|
+
app.registerTypes(this);
|
|
308
310
|
}
|
|
309
311
|
/**
|
|
310
312
|
* The AWS generated URL of the Function.
|
|
@@ -493,12 +495,11 @@ export class Function extends CDKFunction {
|
|
|
493
495
|
}
|
|
494
496
|
static fromDefinition(scope, id, definition, inheritedProps, inheritErrorMessage) {
|
|
495
497
|
if (typeof definition === "string") {
|
|
496
|
-
|
|
498
|
+
return new Function(scope, id, {
|
|
497
499
|
...(inheritedProps || {}),
|
|
498
500
|
handler: definition,
|
|
501
|
+
_doNotAllowOthersToBind: true,
|
|
499
502
|
});
|
|
500
|
-
fn._doNotAllowOthersToBind = true;
|
|
501
|
-
return fn;
|
|
502
503
|
}
|
|
503
504
|
else if (definition instanceof Function) {
|
|
504
505
|
if (inheritedProps && Object.keys(inheritedProps).length > 0) {
|
|
@@ -511,9 +512,10 @@ export class Function extends CDKFunction {
|
|
|
511
512
|
throw new Error(`Please use sst.Function instead of lambda.Function for the "${id}" Function.`);
|
|
512
513
|
}
|
|
513
514
|
else if (definition.handler !== undefined) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
515
|
+
return new Function(scope, id, {
|
|
516
|
+
...Function.mergeProps(inheritedProps, definition),
|
|
517
|
+
_doNotAllowOthersToBind: true,
|
|
518
|
+
});
|
|
517
519
|
}
|
|
518
520
|
throw new Error(`Invalid function definition for the "${id}" Function`);
|
|
519
521
|
}
|
package/constructs/Job.js
CHANGED
|
@@ -72,6 +72,7 @@ export class Job extends Construct {
|
|
|
72
72
|
...props,
|
|
73
73
|
runtime: this.convertJobRuntimeToFunctionRuntime(),
|
|
74
74
|
});
|
|
75
|
+
app.registerTypes(this);
|
|
75
76
|
}
|
|
76
77
|
getConstructMetadata() {
|
|
77
78
|
return {
|
|
@@ -167,7 +168,7 @@ export class Job extends Construct {
|
|
|
167
168
|
// Note: make the invoker function the same ID as the Job
|
|
168
169
|
// construct so users can identify the invoker function
|
|
169
170
|
// in the Console.
|
|
170
|
-
|
|
171
|
+
return new Function(this, this.node.id, {
|
|
171
172
|
...this.props,
|
|
172
173
|
runtime: this.convertJobRuntimeToFunctionRuntime(),
|
|
173
174
|
memorySize: 1024,
|
|
@@ -176,9 +177,8 @@ export class Job extends Construct {
|
|
|
176
177
|
...this.props.environment,
|
|
177
178
|
SST_DEBUG_JOB: "true",
|
|
178
179
|
},
|
|
180
|
+
_doNotAllowOthersToBind: true,
|
|
179
181
|
});
|
|
180
|
-
fn._doNotAllowOthersToBind = true;
|
|
181
|
-
return fn;
|
|
182
182
|
}
|
|
183
183
|
createLogRetention() {
|
|
184
184
|
const { logRetention } = this.props;
|