-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLambdaEndpoint.ts
More file actions
39 lines (33 loc) · 1.44 KB
/
LambdaEndpoint.ts
File metadata and controls
39 lines (33 loc) · 1.44 KB
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
33
34
35
36
37
38
39
import {IResource, LambdaIntegration} from "aws-cdk-lib/aws-apigateway"
import {IRole} from "aws-cdk-lib/aws-iam"
import {HttpMethod, IFunction} from "aws-cdk-lib/aws-lambda"
import {Construct} from "constructs"
export interface LambdaFunctionHolder {
/** Lambda invoked by this API resource method. */
readonly function: IFunction
}
export interface LambdaEndpointProps {
/** Parent API resource under which this endpoint path is created. */
parentResource: IResource
/** Path segment added beneath the parent resource. */
readonly resourceName: string
/** HTTP method exposed on the created API resource. */
readonly method: HttpMethod
/** Role assumed by API Gateway when invoking the integration Lambda. */
restApiGatewayRole: IRole
/** Lambda reference used by the generated integration. */
lambdaFunction: LambdaFunctionHolder
}
/** Adds a child API resource and wires it to a Lambda integration with explicit credentials. */
export class LambdaEndpoint extends Construct {
resource: IResource
/** Creates the resource/method pair and stores the resulting API resource handle. */
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
}
}