DEV Community

Discussion on: Reduce Lambda invocations and code boilerplate by adding a JSON Schema Validator to your API Gateway

Collapse
 
mehmetayan84 profile image
mehmetayan84

thank you for the post. it is very helpful but when you have lambda and api gateway in different stacks, you will get a cyclic reference error. and is there any solution for this one? or think about another example, you are passing api-gateway stack as a resource to lambda constructor as you want to create multiple lambdas in any other stack. for this example where this requestValidation should be added.

Collapse
 
dvddpl profile image
Davide de Paolis

SchemaValidator is a property/setting of the APIGateway not of the Lambda, so having a Lambda in a different stack, makes no difference.
In the stacks where the lambda is defined there will be no mention of the gateway api. In the stack where you create the gateway api, yes, you need to reference/import you lambda in order to create the lambdaIntegration.

new apigateway.LambdaIntegration(myLambda)