sst 2.31.0 → 2.32.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/constructs/App.js +7 -7
- package/constructs/AppSyncApi.d.ts +1 -0
- package/constructs/AppSyncApi.js +100 -26
- package/constructs/Distribution.d.ts +5 -10
- package/constructs/Distribution.js +6 -4
- package/constructs/Function.d.ts +6 -6
- package/constructs/Function.js +4 -4
- package/constructs/Job.js +1 -1
- package/constructs/NextjsSite.d.ts +13 -1
- package/constructs/NextjsSite.js +196 -35
- package/constructs/Service.d.ts +0 -1
- package/constructs/Service.js +1 -2
- package/constructs/SsrSite.d.ts +54 -17
- package/constructs/SsrSite.js +58 -48
- package/constructs/StaticSite.js +3 -2
- package/package.json +2 -2
- package/support/custom-resources/index.mjs +8510 -8439
package/constructs/App.js
CHANGED
|
@@ -264,28 +264,28 @@ export class App extends CDKApp {
|
|
|
264
264
|
const functions = useFunctions();
|
|
265
265
|
const sourcemaps = functions.sourcemaps.forStack(child.stackName);
|
|
266
266
|
if (sourcemaps.length) {
|
|
267
|
-
const policy = new Policy(child, "
|
|
267
|
+
const policy = new Policy(child, "SourcemapUploaderPolicy", {
|
|
268
268
|
statements: [
|
|
269
269
|
new PolicyStatement({
|
|
270
270
|
effect: Effect.ALLOW,
|
|
271
271
|
actions: ["s3:GetObject", "s3:PutObject"],
|
|
272
272
|
resources: [
|
|
273
|
-
sourcemaps[0].
|
|
273
|
+
sourcemaps[0].srcBucket.bucketArn + "/*",
|
|
274
274
|
`arn:${child.partition}:s3:::${bootstrap.bucket}/*`,
|
|
275
275
|
],
|
|
276
276
|
}),
|
|
277
277
|
],
|
|
278
278
|
});
|
|
279
279
|
child.customResourceHandler.role?.attachInlinePolicy(policy);
|
|
280
|
-
const resource = new CustomResource(child, "
|
|
280
|
+
const resource = new CustomResource(child, "SourcemapUploader", {
|
|
281
281
|
serviceToken: child.customResourceHandler.functionArn,
|
|
282
|
-
resourceType: "Custom::
|
|
282
|
+
resourceType: "Custom::SourcemapUploader",
|
|
283
283
|
properties: {
|
|
284
284
|
app: this.name,
|
|
285
285
|
stage: this.stage,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
tarBucket: bootstrap.bucket,
|
|
287
|
+
srcBucket: sourcemaps[0].srcBucket.bucketName,
|
|
288
|
+
sourcemaps: sourcemaps.map((s) => [s.tarKey, s.srcKey]),
|
|
289
289
|
},
|
|
290
290
|
});
|
|
291
291
|
resource.node.addDependency(policy);
|
package/constructs/AppSyncApi.js
CHANGED
|
@@ -11,11 +11,12 @@ 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 { Stack } from "./Stack.js";
|
|
14
15
|
import * as appSyncApiDomain from "./util/appSyncApiDomain.js";
|
|
15
16
|
import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
16
17
|
import { Function as Fn, } from "./Function.js";
|
|
17
18
|
import { useProject } from "../project.js";
|
|
18
|
-
import { GraphqlApi, MappingTemplate as CDKMappingTemplate, SchemaFile, Definition, } from "aws-cdk-lib/aws-appsync";
|
|
19
|
+
import { GraphqlApi, MappingTemplate as CDKMappingTemplate, Resolver, SchemaFile, Definition, LambdaDataSource, DynamoDbDataSource, RdsDataSource, OpenSearchDataSource, HttpDataSource, NoneDataSource, } from "aws-cdk-lib/aws-appsync";
|
|
19
20
|
/////////////////////
|
|
20
21
|
// Construct
|
|
21
22
|
/////////////////////
|
|
@@ -327,58 +328,110 @@ export class AppSyncApi extends Construct {
|
|
|
327
328
|
// Lambda function
|
|
328
329
|
if (Fn.isInlineDefinition(dsValue)) {
|
|
329
330
|
lambda = Fn.fromDefinition(scope, `Lambda_${dsKey}`, dsValue, this.props.defaults?.function, `Cannot define defaults.function when a Function is passed in to the "${dsKey} data source`);
|
|
330
|
-
dataSource = this.
|
|
331
|
+
dataSource = this.isSameStack(scope)
|
|
332
|
+
? this.cdk.graphqlApi.addLambdaDataSource(dsKey, lambda)
|
|
333
|
+
: new LambdaDataSource(scope, dsKey, {
|
|
334
|
+
api: this.cdk.graphqlApi,
|
|
335
|
+
lambdaFunction: lambda,
|
|
336
|
+
});
|
|
331
337
|
}
|
|
332
338
|
// DynamoDb ds
|
|
333
339
|
else if (dsValue.type === "dynamodb") {
|
|
334
|
-
|
|
340
|
+
const dsTable = dsValue.table
|
|
335
341
|
? dsValue.table.cdk.table
|
|
336
|
-
: dsValue.cdk?.dataSource?.table
|
|
342
|
+
: dsValue.cdk?.dataSource?.table;
|
|
343
|
+
const dsOptions = {
|
|
337
344
|
name: dsValue.name,
|
|
338
345
|
description: dsValue.description,
|
|
339
|
-
}
|
|
346
|
+
};
|
|
347
|
+
dataSource = this.isSameStack(scope)
|
|
348
|
+
? this.cdk.graphqlApi.addDynamoDbDataSource(dsKey, dsTable, dsOptions)
|
|
349
|
+
: new DynamoDbDataSource(scope, dsKey, {
|
|
350
|
+
api: this.cdk.graphqlApi,
|
|
351
|
+
table: dsTable,
|
|
352
|
+
...dsOptions,
|
|
353
|
+
});
|
|
340
354
|
}
|
|
341
355
|
// RDS ds
|
|
342
356
|
else if (dsValue.type === "rds") {
|
|
343
|
-
|
|
357
|
+
const dsCluster = dsValue.rds
|
|
344
358
|
? dsValue.rds.cdk.cluster
|
|
345
|
-
: dsValue.cdk?.dataSource?.serverlessCluster
|
|
359
|
+
: dsValue.cdk?.dataSource?.serverlessCluster;
|
|
360
|
+
const dsSecret = dsValue.rds
|
|
346
361
|
? dsValue.rds.cdk.cluster.secret
|
|
347
|
-
: dsValue.cdk?.dataSource?.secretStore
|
|
362
|
+
: dsValue.cdk?.dataSource?.secretStore;
|
|
363
|
+
const dsDatabaseName = dsValue.rds
|
|
348
364
|
? dsValue.databaseName || dsValue.rds.defaultDatabaseName
|
|
349
|
-
: dsValue.cdk?.dataSource?.databaseName
|
|
365
|
+
: dsValue.cdk?.dataSource?.databaseName;
|
|
366
|
+
const dsOptions = {
|
|
350
367
|
name: dsValue.name,
|
|
351
368
|
description: dsValue.description,
|
|
352
|
-
}
|
|
369
|
+
};
|
|
370
|
+
dataSource = this.isSameStack(scope)
|
|
371
|
+
? this.cdk.graphqlApi.addRdsDataSource(dsKey, dsCluster, dsSecret, dsDatabaseName, dsOptions)
|
|
372
|
+
: new RdsDataSource(scope, dsKey, {
|
|
373
|
+
api: this.cdk.graphqlApi,
|
|
374
|
+
serverlessCluster: dsCluster,
|
|
375
|
+
secretStore: dsSecret,
|
|
376
|
+
databaseName: dsDatabaseName,
|
|
377
|
+
...dsOptions,
|
|
378
|
+
});
|
|
353
379
|
}
|
|
354
380
|
// OpenSearch ds
|
|
355
381
|
else if (dsValue.type === "open_search") {
|
|
356
|
-
|
|
382
|
+
const dsOptions = {
|
|
357
383
|
name: dsValue.name,
|
|
358
384
|
description: dsValue.description,
|
|
359
|
-
}
|
|
385
|
+
};
|
|
386
|
+
dataSource = this.isSameStack(scope)
|
|
387
|
+
? this.cdk.graphqlApi.addOpenSearchDataSource(dsKey, dsValue.cdk?.dataSource?.domain, dsOptions)
|
|
388
|
+
: new OpenSearchDataSource(scope, dsKey, {
|
|
389
|
+
api: this.cdk.graphqlApi,
|
|
390
|
+
domain: dsValue.cdk?.dataSource?.domain,
|
|
391
|
+
...dsOptions,
|
|
392
|
+
});
|
|
360
393
|
}
|
|
361
394
|
// Http ds
|
|
362
395
|
else if (dsValue.type === "http") {
|
|
363
|
-
|
|
396
|
+
const dsOptions = {
|
|
364
397
|
name: dsValue.name,
|
|
365
398
|
description: dsValue.description,
|
|
366
|
-
}
|
|
399
|
+
};
|
|
400
|
+
dataSource = this.isSameStack(scope)
|
|
401
|
+
? this.cdk.graphqlApi.addHttpDataSource(dsKey, dsValue.endpoint, dsOptions)
|
|
402
|
+
: new HttpDataSource(scope, dsKey, {
|
|
403
|
+
api: this.cdk.graphqlApi,
|
|
404
|
+
endpoint: dsValue.endpoint,
|
|
405
|
+
...dsOptions,
|
|
406
|
+
});
|
|
367
407
|
}
|
|
368
408
|
// Http ds
|
|
369
409
|
else if (dsValue.type === "none") {
|
|
370
|
-
|
|
410
|
+
const dsOptions = {
|
|
371
411
|
name: dsValue.name,
|
|
372
412
|
description: dsValue.description,
|
|
373
|
-
}
|
|
413
|
+
};
|
|
414
|
+
dataSource = this.isSameStack(scope)
|
|
415
|
+
? this.cdk.graphqlApi.addNoneDataSource(dsKey, dsOptions)
|
|
416
|
+
: new NoneDataSource(scope, dsKey, {
|
|
417
|
+
api: this.cdk.graphqlApi,
|
|
418
|
+
...dsOptions,
|
|
419
|
+
});
|
|
374
420
|
}
|
|
375
421
|
// Lambda ds
|
|
376
422
|
else {
|
|
377
423
|
lambda = Fn.fromDefinition(scope, `Lambda_${dsKey}`, dsValue.function, this.props.defaults?.function, `Cannot define defaults.function when a Function is passed in to the "${dsKey} data source`);
|
|
378
|
-
|
|
424
|
+
const dsOptions = {
|
|
379
425
|
name: dsValue.name,
|
|
380
426
|
description: dsValue.description,
|
|
381
|
-
}
|
|
427
|
+
};
|
|
428
|
+
dataSource = this.isSameStack(scope)
|
|
429
|
+
? this.cdk.graphqlApi.addLambdaDataSource(dsKey, lambda, dsOptions)
|
|
430
|
+
: new LambdaDataSource(scope, dsKey, {
|
|
431
|
+
api: this.cdk.graphqlApi,
|
|
432
|
+
lambdaFunction: lambda,
|
|
433
|
+
...dsOptions,
|
|
434
|
+
});
|
|
382
435
|
}
|
|
383
436
|
this.dataSourcesByDsKey[dsKey] = dataSource;
|
|
384
437
|
if (lambda) {
|
|
@@ -423,7 +476,12 @@ export class AppSyncApi extends Construct {
|
|
|
423
476
|
resValue = resValue;
|
|
424
477
|
lambda = Fn.fromDefinition(scope, `Lambda_${typeName}_${fieldName}`, resValue.function, this.props.defaults?.function, `Cannot define defaults.function when a Function is passed in to the "${resKey} resolver`);
|
|
425
478
|
dataSourceKey = this.buildDataSourceKey(typeName, fieldName);
|
|
426
|
-
dataSource = this.
|
|
479
|
+
dataSource = this.isSameStack(scope)
|
|
480
|
+
? this.cdk.graphqlApi.addLambdaDataSource(dataSourceKey, lambda)
|
|
481
|
+
: new LambdaDataSource(scope, dataSourceKey, {
|
|
482
|
+
api: this.cdk.graphqlApi,
|
|
483
|
+
lambdaFunction: lambda,
|
|
484
|
+
});
|
|
427
485
|
resolverProps = {
|
|
428
486
|
requestMappingTemplate: this.buildMappingTemplate(resValue.requestMapping),
|
|
429
487
|
responseMappingTemplate: this.buildMappingTemplate(resValue.responseMapping),
|
|
@@ -446,7 +504,12 @@ export class AppSyncApi extends Construct {
|
|
|
446
504
|
resValue = resValue;
|
|
447
505
|
lambda = Fn.fromDefinition(scope, `Lambda_${typeName}_${fieldName}`, resValue, this.props.defaults?.function, `Cannot define defaults.function when a Function is passed in to the "${resKey} resolver`);
|
|
448
506
|
dataSourceKey = this.buildDataSourceKey(typeName, fieldName);
|
|
449
|
-
dataSource = this.
|
|
507
|
+
dataSource = this.isSameStack(scope)
|
|
508
|
+
? this.cdk.graphqlApi.addLambdaDataSource(dataSourceKey, lambda)
|
|
509
|
+
: new LambdaDataSource(scope, dataSourceKey, {
|
|
510
|
+
api: this.cdk.graphqlApi,
|
|
511
|
+
lambdaFunction: lambda,
|
|
512
|
+
});
|
|
450
513
|
resolverProps = {};
|
|
451
514
|
}
|
|
452
515
|
if (lambda) {
|
|
@@ -461,12 +524,20 @@ export class AppSyncApi extends Construct {
|
|
|
461
524
|
///////////////////
|
|
462
525
|
// Create resolver
|
|
463
526
|
///////////////////
|
|
464
|
-
const resolver = this.
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
527
|
+
const resolver = this.isSameStack(scope)
|
|
528
|
+
? this.cdk.graphqlApi.createResolver(`${typeName}${fieldName}Resolver`, {
|
|
529
|
+
dataSource,
|
|
530
|
+
typeName,
|
|
531
|
+
fieldName,
|
|
532
|
+
...resolverProps,
|
|
533
|
+
})
|
|
534
|
+
: new Resolver(scope, `${typeName}${fieldName}Resolver`, {
|
|
535
|
+
api: this.cdk.graphqlApi,
|
|
536
|
+
dataSource,
|
|
537
|
+
typeName,
|
|
538
|
+
fieldName,
|
|
539
|
+
...resolverProps,
|
|
540
|
+
});
|
|
470
541
|
this.resolversByResKey[resKey] = resolver;
|
|
471
542
|
return lambda;
|
|
472
543
|
}
|
|
@@ -492,4 +563,7 @@ export class AppSyncApi extends Construct {
|
|
|
492
563
|
buildDataSourceKey(typeName, fieldName) {
|
|
493
564
|
return `LambdaDS_${typeName}_${fieldName}`;
|
|
494
565
|
}
|
|
566
|
+
isSameStack(scope) {
|
|
567
|
+
return Stack.of(this) === Stack.of(scope);
|
|
568
|
+
}
|
|
495
569
|
}
|
|
@@ -94,15 +94,6 @@ export interface DistributionProps {
|
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
96
|
customDomain?: string | DistributionDomainProps;
|
|
97
|
-
/**
|
|
98
|
-
* The SSR function is deployed to Lambda in a single region. Alternatively, you can enable this option to deploy to Lambda@Edge.
|
|
99
|
-
* @default false
|
|
100
|
-
*/
|
|
101
|
-
/**
|
|
102
|
-
* While deploying, SST waits for the CloudFront cache invalidation process to finish. This ensures that the new content will be served once the deploy command finishes. However, this process can sometimes take more than 5 mins. For non-prod environments it might make sense to pass in `false`. That'll skip waiting for the cache to invalidate and speed up the deploy process.
|
|
103
|
-
* @default false
|
|
104
|
-
*/
|
|
105
|
-
waitForInvalidation?: boolean;
|
|
106
97
|
scopeOverride?: IConstruct;
|
|
107
98
|
cdk: {
|
|
108
99
|
distribution: CdkDistributionProps | IDistribution;
|
|
@@ -132,7 +123,11 @@ export declare class Distribution extends Construct {
|
|
|
132
123
|
hostedZone: IHostedZone | undefined;
|
|
133
124
|
certificate: ICertificate | undefined;
|
|
134
125
|
};
|
|
135
|
-
createInvalidation(
|
|
126
|
+
createInvalidation(props?: {
|
|
127
|
+
version?: string;
|
|
128
|
+
paths?: string[];
|
|
129
|
+
wait?: boolean;
|
|
130
|
+
}): CustomResource;
|
|
136
131
|
private validateCloudFrontDistributionSettings;
|
|
137
132
|
private validateCustomDomainSettings;
|
|
138
133
|
private lookupHostedZone;
|
|
@@ -70,7 +70,8 @@ export class Distribution extends Construct {
|
|
|
70
70
|
certificate: this.certificate,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
createInvalidation(
|
|
73
|
+
createInvalidation(props) {
|
|
74
|
+
const { version, paths, wait } = props ?? {};
|
|
74
75
|
const stack = Stack.of(this);
|
|
75
76
|
const policy = new Policy(this.scope, "CloudFrontInvalidatorPolicy", {
|
|
76
77
|
statements: [
|
|
@@ -91,10 +92,11 @@ export class Distribution extends Construct {
|
|
|
91
92
|
serviceToken: stack.customResourceHandler.functionArn,
|
|
92
93
|
resourceType: "Custom::CloudFrontInvalidator",
|
|
93
94
|
properties: {
|
|
94
|
-
|
|
95
|
+
version: version ||
|
|
96
|
+
Date.now().toString(16) + Math.random().toString(16).slice(2),
|
|
95
97
|
distributionId: this.distribution.distributionId,
|
|
96
|
-
paths: paths ?? ["/*"],
|
|
97
|
-
|
|
98
|
+
paths: [...new Set(paths ?? ["/*"])],
|
|
99
|
+
wait: wait ?? false,
|
|
98
100
|
},
|
|
99
101
|
});
|
|
100
102
|
resource.node.addDependency(policy);
|
package/constructs/Function.d.ts
CHANGED
|
@@ -693,14 +693,14 @@ export declare class Function extends CDKFunction implements SSTConstruct {
|
|
|
693
693
|
export declare const useFunctions: () => {
|
|
694
694
|
sourcemaps: {
|
|
695
695
|
add(stack: string, source: {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
696
|
+
srcBucket: IBucket;
|
|
697
|
+
srcKey: string;
|
|
698
|
+
tarKey: string;
|
|
699
699
|
}): void;
|
|
700
700
|
forStack(stack: string): {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
701
|
+
srcBucket: IBucket;
|
|
702
|
+
srcKey: string;
|
|
703
|
+
tarKey: string;
|
|
704
704
|
}[];
|
|
705
705
|
};
|
|
706
706
|
fromID(id: string): FunctionProps | undefined;
|
package/constructs/Function.js
CHANGED
|
@@ -211,7 +211,7 @@ export class Function extends CDKFunction {
|
|
|
211
211
|
...(props.container?.buildArgs
|
|
212
212
|
? { buildArgs: props.container.buildArgs }
|
|
213
213
|
: {}),
|
|
214
|
-
exclude: [".sst"],
|
|
214
|
+
exclude: [".sst/dist", ".sst/artifacts"],
|
|
215
215
|
ignoreMode: IgnoreMode.GLOB,
|
|
216
216
|
}),
|
|
217
217
|
handler: CDKHandler.FROM_IMAGE,
|
|
@@ -257,9 +257,9 @@ export class Function extends CDKFunction {
|
|
|
257
257
|
});
|
|
258
258
|
await fs.rm(result.sourcemap);
|
|
259
259
|
useFunctions().sourcemaps.add(stack.stackName, {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
srcBucket: asset.bucket,
|
|
261
|
+
srcKey: asset.s3ObjectKey,
|
|
262
|
+
tarKey: this.functionArn,
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
// Update code
|
package/constructs/Job.js
CHANGED
|
@@ -214,7 +214,7 @@ export class Job extends Construct {
|
|
|
214
214
|
: Platform.custom("linux/amd64"),
|
|
215
215
|
file: container?.file,
|
|
216
216
|
buildArgs: container?.buildArgs,
|
|
217
|
-
exclude: [".sst"],
|
|
217
|
+
exclude: [".sst/dist", ".sst/artifacts"],
|
|
218
218
|
ignoreMode: IgnoreMode.GLOB,
|
|
219
219
|
});
|
|
220
220
|
image.repository?.grantPull(this.job.role);
|
|
@@ -123,7 +123,11 @@ type NextjsSiteNormalizedProps = NextjsSiteProps & SsrSiteNormalizedProps;
|
|
|
123
123
|
*/
|
|
124
124
|
export declare class NextjsSite extends SsrSite {
|
|
125
125
|
props: NextjsSiteNormalizedProps;
|
|
126
|
-
private
|
|
126
|
+
private _routes?;
|
|
127
|
+
private routesManifest?;
|
|
128
|
+
private appPathRoutesManifest?;
|
|
129
|
+
private appPathsManifest?;
|
|
130
|
+
private pagesManifest?;
|
|
127
131
|
constructor(scope: Construct, id: string, props?: NextjsSiteProps);
|
|
128
132
|
static buildDefaultServerCachePolicyProps(): CachePolicyProps;
|
|
129
133
|
protected plan(bucket: Bucket): {
|
|
@@ -335,10 +339,18 @@ export declare class NextjsSite extends SsrSite {
|
|
|
335
339
|
};
|
|
336
340
|
};
|
|
337
341
|
private wrapServerFunction;
|
|
342
|
+
private removeSourcemaps;
|
|
338
343
|
private useRoutes;
|
|
344
|
+
private useRoutesManifest;
|
|
345
|
+
private useAppPathRoutesManifest;
|
|
346
|
+
private useAppPathsManifest;
|
|
347
|
+
private usePagesManifest;
|
|
339
348
|
private getBuildId;
|
|
349
|
+
private getSourcemapForAppRoute;
|
|
350
|
+
private getSourcemapForPagesRoute;
|
|
340
351
|
private isPerRouteLoggingEnabled;
|
|
341
352
|
private disableDefaultLogging;
|
|
353
|
+
private uploadSourcemaps;
|
|
342
354
|
private static buildCloudWatchRouteName;
|
|
343
355
|
private static buildCloudWatchRouteHash;
|
|
344
356
|
static _test: {
|