sst 2.0.4 → 2.0.5

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.
@@ -164,7 +164,7 @@ export interface ApiAccessLogProps extends apigV2AccessLog.AccessLogProps {
164
164
  }
165
165
  export interface ApiProps<Authorizers extends Record<string, ApiAuthorizer> = Record<string, ApiAuthorizer>, AuthorizerKeys = keyof Authorizers> {
166
166
  /**
167
- * Define the routes for the API. Can be a function, proxy to another API, or point to an ALB
167
+ * Define the routes for the API. Can be a function, proxy to another API, or point to an load balancer
168
168
  *
169
169
  * @example
170
170
  *
@@ -393,7 +393,7 @@ export interface ApiProps<Authorizers extends Record<string, ApiAuthorizer> = Re
393
393
  httpStages?: Omit<apig.HttpStageProps, "httpApi">[];
394
394
  };
395
395
  }
396
- export type ApiRouteProps<AuthorizerKeys> = FunctionInlineDefinition | ApiFunctionRouteProps<AuthorizerKeys> | ApiHttpRouteProps<AuthorizerKeys> | ApiAlbRouteProps<AuthorizerKeys> | ApiGraphQLRouteProps<AuthorizerKeys>;
396
+ export type ApiRouteProps<AuthorizerKeys> = FunctionInlineDefinition | ApiFunctionRouteProps<AuthorizerKeys> | ApiHttpRouteProps<AuthorizerKeys> | ApiAlbRouteProps<AuthorizerKeys> | ApiNlbRouteProps<AuthorizerKeys> | ApiGraphQLRouteProps<AuthorizerKeys>;
397
397
  interface ApiBaseRouteProps<AuthorizerKeys = string> {
398
398
  authorizer?: "none" | "iam" | (string extends AuthorizerKeys ? Omit<AuthorizerKeys, "none" | "iam"> : AuthorizerKeys);
399
399
  authorizationScopes?: string[];
@@ -485,6 +485,31 @@ export interface ApiAlbRouteProps<AuthorizersKeys> extends ApiBaseRouteProps<Aut
485
485
  integration?: apigIntegrations.HttpAlbIntegrationProps;
486
486
  };
487
487
  }
488
+ /**
489
+ * Specify a route handler that forwards to an NLB
490
+ *
491
+ * @example
492
+ * ```js
493
+ * api.addRoutes(stack, {
494
+ * "GET /notes/{id}": {
495
+ * type: "nlb",
496
+ * cdk: {
497
+ * nlbListener: listener,
498
+ * }
499
+ * }
500
+ * });
501
+ * ```
502
+ */
503
+ export interface ApiNlbRouteProps<AuthorizersKeys> extends ApiBaseRouteProps<AuthorizersKeys> {
504
+ type: "nlb";
505
+ cdk: {
506
+ /**
507
+ * The listener to the application load balancer used for the integration.
508
+ */
509
+ nlbListener: elb.INetworkListener;
510
+ integration?: apigIntegrations.HttpNlbIntegrationProps;
511
+ };
512
+ }
488
513
  /**
489
514
  * Specify a route handler that handles GraphQL queries using Pothos
490
515
  *
@@ -706,7 +731,7 @@ export declare class Api<Authorizers extends Record<string, ApiAuthorizer> = Rec
706
731
  output: string | undefined;
707
732
  commands: string[] | undefined;
708
733
  } | {
709
- type: "lambda_function" | "url" | "alb";
734
+ type: "lambda_function" | "url" | "alb" | "nlb";
710
735
  route: string;
711
736
  fn?: undefined;
712
737
  schema?: undefined;
@@ -731,6 +756,7 @@ export declare class Api<Authorizers extends Record<string, ApiAuthorizer> = Rec
731
756
  private addRoute;
732
757
  private createHttpIntegration;
733
758
  private createAlbIntegration;
759
+ private createNlbIntegration;
734
760
  protected createGraphQLIntegration(scope: Construct, routeKey: string, routeProps: ApiGraphQLRouteProps<keyof Authorizers>, postfixName: string): apig.HttpRouteIntegration;
735
761
  protected createCdkFunctionIntegration(scope: Construct, routeKey: string, routeProps: ApiFunctionRouteProps<keyof Authorizers>, postfixName: string): apig.HttpRouteIntegration;
736
762
  protected createFunctionIntegration(scope: Construct, routeKey: string, routeProps: ApiFunctionRouteProps<keyof Authorizers>, postfixName: string): apig.HttpRouteIntegration;
package/constructs/Api.js CHANGED
@@ -444,6 +444,12 @@ export class Api extends Construct {
444
444
  this.createAlbIntegration(scope, routeKey, routeValue, postfixName),
445
445
  ];
446
446
  }
447
+ if (routeValue.type === "nlb") {
448
+ return [
449
+ routeValue,
450
+ this.createNlbIntegration(scope, routeKey, routeValue, postfixName),
451
+ ];
452
+ }
447
453
  if (routeValue.type === "url") {
448
454
  return [
449
455
  routeValue,
@@ -470,7 +476,7 @@ export class Api extends Construct {
470
476
  }
471
477
  if ("handler" in routeValue)
472
478
  throw new Error(`Function definition must be nested under the "function" key in the route props for "${routeKey}". ie. { function: { handler: "myfunc.handler" } }`);
473
- throw new Error(`Invalid route type for "${routeKey}". Must be one of: alb, url, function`);
479
+ throw new Error(`Invalid route type for "${routeKey}". Must be one of: alb, nlb, url, or function`);
474
480
  })();
475
481
  const { authorizationType, authorizer, authorizationScopes } = this.buildRouteAuth(routeProps);
476
482
  const route = new apig.HttpRoute(scope, `Route_${postfixName}`, {
@@ -520,6 +526,18 @@ export class Api extends Construct {
520
526
  };
521
527
  return integration;
522
528
  }
529
+ createNlbIntegration(scope, routeKey, routeProps, postfixName) {
530
+ ///////////////////
531
+ // Create integration
532
+ ///////////////////
533
+ const integration = new apigIntegrations.HttpNlbIntegration(`Integration_${postfixName}`, routeProps.cdk?.nlbListener, routeProps.cdk?.integration);
534
+ // Store route
535
+ this.routesData[routeKey] = {
536
+ type: "nlb",
537
+ nlb: routeProps.cdk?.nlbListener,
538
+ };
539
+ return integration;
540
+ }
523
541
  createGraphQLIntegration(scope, routeKey, routeProps, postfixName) {
524
542
  const result = this.createFunctionIntegration(scope, routeKey, {
525
543
  ...routeProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },