Skip to content

Instantly share code, notes, and snippets.

@fl0wo
Last active December 12, 2022 20:12
Show Gist options
  • Save fl0wo/2a683e1949b2dc8ae5f7f94ff1383b44 to your computer and use it in GitHub Desktop.
Save fl0wo/2a683e1949b2dc8ae5f7f94ff1383b44 to your computer and use it in GitHub Desktop.
AddPrivateEndpointsToRestApiGateway
export const addEndpointsToRestApiGateway = (
stack: Construct,
api:RestApi,
apis: Array<ApiRestEndpoint>) => {
apis.forEach(rest => {
const route = api.root.addResource(rest.path);
route.addMethod(
rest.https_methods[0],
new LambdaIntegration(rest.fun),
);
});
return api;
}
export const addPrivateEndpointsToRestApiGateway = (
scope: Construct,
api: RestApi,
authorizer: Authorizer,
authorizationType: AuthorizationType,
apis: Array<ApiRestEndpoint>
) => {
apis.forEach(rest => {
const route = api.root.addResource(rest.path);
route.addMethod(
rest.https_methods[0],
new LambdaIntegration(rest.fun),
{
authorizer: authorizer,
authorizationType: authorizationType
}
);
});
return api;
}
import {NodejsFunction} from "aws-cdk-lib/aws-lambda-nodejs";
import {HttpMethod} from "aws-cdk-lib/aws-events";
export interface ApiRestEndpoint {
description: string,
id: string,
fun: NodejsFunction,
https_methods: Array<HttpMethod>,
path: string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment