-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLambdaEndpoint.ts
More file actions
32 lines (26 loc) · 956 Bytes
/
LambdaEndpoint.ts
File metadata and controls
32 lines (26 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {IResource, LambdaIntegration} from "aws-cdk-lib/aws-apigateway"
import {IRole} from "aws-cdk-lib/aws-iam"
import {IFunction} from "aws-cdk-lib/aws-lambda"
import {HttpMethod} from "aws-cdk-lib/aws-lambda"
import {Construct} from "constructs"
export interface LambdaFunctionHolder {
readonly function: IFunction
}
export interface LambdaEndpointProps {
parentResource: IResource
readonly resourceName: string
readonly method: HttpMethod
restApiGatewayRole: IRole
lambdaFunction: LambdaFunctionHolder
}
export class LambdaEndpoint extends Construct {
resource: IResource
public constructor(scope: Construct, id: string, props: LambdaEndpointProps) {
super(scope, id)
const resource = props.parentResource.addResource(props.resourceName)
resource.addMethod(props.method, new LambdaIntegration(props.lambdaFunction.function, {
credentialsRole: props.restApiGatewayRole
}))
this.resource = resource
}
}