Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
ApiGatewayV2: link resources for all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Oct 15, 2024
1 parent b96c99f commit ecac521
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions platform/src/components/aws/apigatewayv2-lambda-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface Args extends ApiGatewayV2BaseRouteArgs {
* Takes the handler path, the function args, or a function ARN.
*/
handler: Input<string | FunctionArgs | FunctionArn>;
/**
* The resources to link to the route function.
*/
handlerLink?: FunctionArgs["link"];
/**
* @internal
*/
Expand Down Expand Up @@ -66,6 +70,7 @@ export class ApiGatewayV2LambdaRoute extends Component {
args.handler,
{
description: interpolate`${api.name} route ${route}`,
link: args.handlerLink,
},
args.handlerTransform,
{ parent: self },
Expand Down
17 changes: 17 additions & 0 deletions platform/src/components/aws/apigatewayv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ interface ApiGatewayV2CorsArgs {
}

export interface ApiGatewayV2Args {
/**
* [Link resources](/docs/linking/) to all your API Gateway routes.
*
* Linked resources will be merged with the resources linked to each route.
*
* @example
*
* Takes a list of resources to link to all the routes.
*
* ```js
* {
* link: [bucket, stripeKey]
* }
* ```
*/
link?: FunctionArgs["link"];
/**
* Set a custom domain for your HTTP API.
*
Expand Down Expand Up @@ -1061,6 +1077,7 @@ export class ApiGatewayV2 extends Component implements Link.Linkable {
},
route,
handler,
handlerLink: this.constructorArgs.link,
handlerTransform: this.constructorArgs.transform?.route?.handler,
...transformed[1],
},
Expand Down
2 changes: 1 addition & 1 deletion platform/src/components/aws/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export interface FunctionArgs {
* [Link resources](/docs/linking/) to your function. This will:
*
* 1. Grant the permissions needed to access the resources.
* 2. Allow you to access it in your site using the [SDK](/docs/reference/sdk/).
* 2. Allow you to access it in your function using the [SDK](/docs/reference/sdk/).
*
* @example
*
Expand Down
8 changes: 7 additions & 1 deletion platform/src/components/aws/helpers/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type FunctionBuilder = Output<{
export function functionBuilder(
name: string,
definition: Input<string | FunctionArn | FunctionArgs>,
override: Pick<FunctionArgs, "description" | "permissions">,
override: Pick<FunctionArgs, "description" | "link" | "permissions">,
argsTransform?: Transform<FunctionArgs>,
opts?: ComponentResourceOptions,
): FunctionBuilder {
Expand Down Expand Up @@ -64,6 +64,12 @@ export function functionBuilder(
{
...definition,
...override,
link: all([definition.link, override?.link]).apply(
([link, overrideLink]) => [
...(link ?? []),
...(overrideLink ?? []),
],
),
permissions: all([
definition.permissions,
override?.permissions,
Expand Down

0 comments on commit ecac521

Please sign in to comment.