@@ -4,6 +4,7 @@ import {HttpMethod} from "aws-cdk-lib/aws-lambda"
44import { IRole } from "aws-cdk-lib/aws-iam"
55import { LambdaFunction } from "../LambdaFunction"
66
7+ // Props for constructing an API Gateway endpoint backed by a Lambda function.
78export interface LambdaEndpointProps {
89 readonly parentResource : IResource
910 readonly resourceName : string
@@ -12,20 +13,23 @@ export interface LambdaEndpointProps {
1213 readonly lambdaFunction : LambdaFunction
1314}
1415
16+ // Creates an API Gateway resource and method integrated with a Lambda function.
1517export class LambdaEndpoint extends Construct {
1618 public readonly resource : IResource
1719
1820 constructor ( scope : Construct , id : string , props : LambdaEndpointProps ) {
1921 super ( scope , id )
2022
23+ // Add a new resource to the parent resource
2124 const resource = props . parentResource . addResource ( props . resourceName )
2225
23- resource . addMethod ( props . method , new LambdaIntegration ( props . lambdaFunction . function , {
24- credentialsRole : props . restApiGatewayRole
25- } ) )
26+ // Add a method to the resource, integrated with the Lambda function.
27+ resource . addMethod ( props . method , new LambdaIntegration ( props . lambdaFunction . function ) )
2628
27- props . restApiGatewayRole . addManagedPolicy ( props . lambdaFunction . executionPolicy )
29+ // Grant API Gateway's role permission to invoke the Lambda function.
30+ props . lambdaFunction . function . grantInvoke ( props . restApiGatewayRole )
2831
32+ // Expose the resource for potential further use.
2933 this . resource = resource
3034 }
3135}
0 commit comments