sst 2.32.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.
@@ -546,5 +546,6 @@ export declare class AppSyncApi extends Construct implements SSTConstruct {
546
546
  private normalizeResolverKey;
547
547
  private buildMappingTemplate;
548
548
  private buildDataSourceKey;
549
+ private isSameStack;
549
550
  }
550
551
  export {};
@@ -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.cdk.graphqlApi.addLambdaDataSource(dsKey, lambda);
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
- dataSource = this.cdk.graphqlApi.addDynamoDbDataSource(dsKey, dsValue.table
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
- dataSource = this.cdk.graphqlApi.addRdsDataSource(dsKey, dsValue.rds
357
+ const dsCluster = dsValue.rds
344
358
  ? dsValue.rds.cdk.cluster
345
- : dsValue.cdk?.dataSource?.serverlessCluster, dsValue.rds
359
+ : dsValue.cdk?.dataSource?.serverlessCluster;
360
+ const dsSecret = dsValue.rds
346
361
  ? dsValue.rds.cdk.cluster.secret
347
- : dsValue.cdk?.dataSource?.secretStore, dsValue.rds
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
- dataSource = this.cdk.graphqlApi.addOpenSearchDataSource(dsKey, dsValue.cdk?.dataSource?.domain, {
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
- dataSource = this.cdk.graphqlApi.addHttpDataSource(dsKey, dsValue.endpoint, {
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
- dataSource = this.cdk.graphqlApi.addNoneDataSource(dsKey, {
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
- dataSource = this.cdk.graphqlApi.addLambdaDataSource(dsKey, lambda, {
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.cdk.graphqlApi.addLambdaDataSource(dataSourceKey, lambda);
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.cdk.graphqlApi.addLambdaDataSource(dataSourceKey, lambda);
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.cdk.graphqlApi.createResolver(`${typeName}${fieldName}Resolver`, {
465
- dataSource,
466
- typeName,
467
- fieldName,
468
- ...resolverProps,
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
  }
@@ -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,
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);
@@ -644,7 +644,7 @@ export class Service extends Construct {
644
644
  platform: architecture === "arm64" ? Platform.LINUX_ARM64 : Platform.LINUX_AMD64,
645
645
  file: dockerfile,
646
646
  buildArgs: build?.buildArgs,
647
- exclude: [".sst"],
647
+ exclude: [".sst/dist", ".sst/artifacts"],
648
648
  ignoreMode: IgnoreMode.GLOB,
649
649
  });
650
650
  const cfnTask = taskDefinition.node.defaultChild;
@@ -1,7 +1,7 @@
1
1
  import { Construct } from "constructs";
2
2
  import { Bucket, BucketProps, IBucket } from "aws-cdk-lib/aws-s3";
3
3
  import { Function as CdkFunction, FunctionProps as CdkFunctionProps } from "aws-cdk-lib/aws-lambda";
4
- import { ICachePolicy, IResponseHeadersPolicy, AllowedMethods, CachePolicyProps, ErrorResponse } from "aws-cdk-lib/aws-cloudfront";
4
+ import { ICachePolicy, IResponseHeadersPolicy, ViewerProtocolPolicy, AllowedMethods, CachePolicyProps, ErrorResponse } from "aws-cdk-lib/aws-cloudfront";
5
5
  import { Schedule } from "aws-cdk-lib/aws-events";
6
6
  import { DistributionDomainProps } from "./Distribution.js";
7
7
  import { SSTConstruct } from "./Construct.js";
@@ -361,6 +361,19 @@ export interface SsrSiteProps {
361
361
  * from the server rendering Lambda.
362
362
  */
363
363
  responseHeadersPolicy?: IResponseHeadersPolicy;
364
+ /**
365
+ * Override the CloudFront viewer protocol policy properties.
366
+ * @default ViewerProtocolPolicy.REDIRECT_TO_HTTPS
367
+ * @example
368
+ * ```js
369
+ * import { ViewerProtocolPolicy } from "aws-cdk-lib/aws-cloudfront";
370
+ *
371
+ * cdk: {
372
+ * viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
373
+ * }
374
+ * ```
375
+ */
376
+ viewerProtocolPolicy?: ViewerProtocolPolicy;
364
377
  server?: Pick<CdkFunctionProps, "layers" | "vpc" | "vpcSubnets" | "securityGroups" | "allowAllOutbound" | "allowPublicSubnet" | "architecture" | "logRetention"> & Pick<FunctionProps, "copyFiles">;
365
378
  };
366
379
  }
@@ -308,7 +308,7 @@ export class SsrSite extends Construct {
308
308
  if (behavior.cacheType === "static") {
309
309
  return {
310
310
  origin,
311
- viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
311
+ viewerProtocolPolicy: cdk?.viewerProtocolPolicy ?? ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
312
312
  allowedMethods: behavior.allowedMethods ?? AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
313
313
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
314
314
  compress: true,
@@ -326,7 +326,7 @@ export class SsrSite extends Construct {
326
326
  }
327
327
  else if (behavior.cacheType === "server") {
328
328
  return {
329
- viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
329
+ viewerProtocolPolicy: cdk?.viewerProtocolPolicy ?? ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
330
330
  origin,
331
331
  allowedMethods: behavior.allowedMethods ?? AllowedMethods.ALLOW_ALL,
332
332
  cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.32.0",
4
+ "version": "2.32.1",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -120,7 +120,7 @@
120
120
  "@types/ws": "^8.5.3",
121
121
  "@types/yargs": "^17.0.13",
122
122
  "archiver": "^5.3.1",
123
- "astro-sst": "2.32.0",
123
+ "astro-sst": "2.32.1",
124
124
  "async": "^3.2.4",
125
125
  "tsx": "^3.12.1",
126
126
  "typescript": "^5.2.2",