-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request validator limit of 20 #9291
Comments
Hello @brian-geoghegan, in Would that be helpful to resolve your issue here? |
A solution for this should be, creating request validators and them in the schema, instead of creating a new request validator each time a schema is created? ${modelName}Validator should just be a generic bodyRequestValidator or whatever one would like to name it?. Here is the response I received from AWS support: Thank you for contacting AWS Premium Support, my name is Sean and I'll be assisting you today. I understand from the case details you are hitting a limit for the Maximum Number of Request Validators for a given API. The limit for this is 20 and cannot be increased- however, these validators are intended to be reused and shared across APIs. Because request validators have three options ( 1.Validate body, 2.Validate query string parameters and headers, 3. Validate body, query string parameters, and headers) more than three validators shouldn't be required. The serverless Framework creates a new Request Validator for every endpoint resource method. In this case you can list existing request validator using get-request-validators [1] CLI and provide the name of existing request validator in the CloudFormation template, so that CloudFormation will not create new request validator every time with random name and this will prevent from exceeding limit. Furthermore, you can use AWSCLI command to list "get-request-validators" [2] and remove "delete-request-validator command" [3] any validator you do not need. After that, you could reuse validators for your future deployments. |
Thanks for clarification @brian-geoghegan - I've checked an in fact, we're creating separate validators which definitely seems unnecessary. I believe we should reuse validators instead of creating new ones. I'll dive deeper into the code to figure out a potential way of reusing them in an efficient and backward-compatible manner. |
Thanks @pgrzesik, a solution I tried was to create the request validator separately and first and create models after it. Could specify the validator separately at a stack level or create generic ones automatically. If you need anything more from me let me know! |
I believe the most reasonable approach would be to create the generic ones automatically whenever they are needed. From what I inspected it seems like we're always creating validators with the following params:
so it suggests that we could have a single validator in the stack that is reused across all |
If you are able to check if it exists already after being created would be ideal instead of recreating it per lambda. Just so that it is only created once and is reused, if you reference the one already created while creating the model schema would be ideal. I think the easiest for you guys could even just create one when an api gateway is created and then use that one if the schema key word appears. That way you can just focus on creating schema models when a lambda needs it. The request validator plugin worked that way. Create a validator on the stack and then attach it to a lambda if you need it(if you also wanted to add a schema) Thanks again for the quick response on this, love the framework! |
Hello @gambit66 - thanks for proposing a PR that will address this issue. I have one concern though - did you confirm that the proposed change is not breaking already existing stacks that will have to recreate the validators? We wouldn't want to introduce any disruptions for existing services. |
Hi @pgrzesik, thank you for taking the time to look at my PR. I have tested this update with a test project to try test all the different scenarios I could think of, such as having 1 function use events.http.request.schemas and another using the old events.http.request.schema property. I also did a deployment using this code for an API project that was getting the |
Thanks for working on this @gambit66 |
FYI @gambit66 : One of our stacks creates the apig reqValidator. I have 2 other stacks using it for their events. If I leave in the reqValidator while deleting references to it. I get the error last reported above. If I remove the reqValidator and all references to it, I have a dependancy error on deploy (below).
The following worked for me.
|
Oh - it took some time for me to understand the solution implemented (and why I was unable to get it to work for me). Right now, serverless framework create a shared Request Validator per stack. Well, I've got more than 20+ stacks so the hard limit of 20 Request Validators per API Gateway is still hit. What I ended up doing, in case someone is struggling with similar issues, was to install these two plugins:
The first resources:
Resources:
ApiGatewayRequestValidator:
Type: AWS::ApiGateway::RequestValidator
Properties:
RestApiId: !Ref ApiGatewayRestApi # Definition omitted
ValidateRequestBody: true
ValidateRequestParameters: true
Name: 'Validate request body and query string parameters'
Outputs:
ApiGatewayRequestValidatorId:
Value: !Ref ApiGatewayRequestValidator
Export:
Name: ApiGatewayRequestValidatorId The functions:
foo:
handler: foo.main
events:
- http:
path: bar/{param}
method: get
cors: true
request:
parameters:
paths:
param: true
reqValidatorName: !ImportValue ApiGatewayRequestValidatorId |
I am running into an issue with request validation. When using event schemas, a model is created and a request validator. The request validator limit per api is 20. So when your reach 21 schema's, 21 validators exist. Thus throwing the error.
Maximum number of Request Validators for this API has been reached. (Service: AmazonApiGateway; Status Code: 429; Error Code: LimitExceededException; Request ID: ; Proxy: null).
and failing a deploy.Could there be a change to reuse validators instead of creating new ones? I contacted AWS and this was the recommended solution, I tried using serverless-request-validator plugin and it creates a reusable validator that you can attach, but the issue still arises with the schema keywork in an event, as it still tries to create a new validator before attaching the existing one.
⚠️⚠️ REPLACE WITH FULL COMMAND NAME
outputInstalled version2.20.0
The text was updated successfully, but these errors were encountered: