-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support Request Validator to the method on API Event #1403
Comments
Thanks for the feature request! We have passed this along to our product team for possible prioritization. Please +1 on the feature to help with prioritization. |
@praneetap this has been raised before. I opened issue #1232 and it was quickly closed in favor of #931 |
+1 |
A temporary solution could be to add a partial DefinitionBody in your ApiGateway resource :
This will add a validator named basic and will add it to every function in your apigateway, thus will enforce validation of the body and parameters (tweak it as you need) |
|
You can generate partial swagger doc. I just did in our templates that needed request body verification. What I posted is exactly what I used combined with something similiar as what is posted in the original post. |
@g-pelletier disregard that last comment. I wasn't thinking. What you posted is what we've had to do for similar workarounds as well. Though I don't think you could really call that a partial swagger doc. |
Sorry, by partial, I meant that you don't need to write the full API code to have it working. SAM will append the other parts, such as Models and Authorizers. |
@praneetap @keetonian could you provide some info on how this relates to #931 and #1232? Those issues seem to suggest that there is work underway yet this issue seems to be still in triage? I'd avoid the swagger workaround if validation support for |
Hi! I was a little bit annoyed with the lack of this feature, so I started hacking away a possible solution. I ended up with a version that works locally using cloud formation packaging/deploy, but I am not sure if it would be eligible for a Pull Request. I would appreciate if anyone would give me a feedback whether this would be useful to the general development of the specification. Basically, I've added properties to the SAM specification
The first one basically injects the following on the generated template:
Then the second would inject this to the API Method:
A sample template would be:
|
Still need "Request Validator" parameter in SAM. |
+1 for "Request Validator" |
+1 |
+++ |
+1 |
1 similar comment
+1 |
++ |
+1 |
1 similar comment
+1 |
Hi! |
+1 |
1 similar comment
+1 |
This is really needed. |
Up |
+1 |
|
+1 |
2 similar comments
+1 |
+1 |
++++++1 |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
+1 (and it's somewhat annoying to have to waste time on this topic) |
I have added a PR to try fix this: #2026 If someone could review and give a +1. |
+1, we need this! |
Ok, so I'm not going mad: I've spent several days trying to get SAM to add a Request Validator. Looks like the PR above will make this simple to do. |
+1 |
Now that the solution was implemented. Can somebody explain to me what is the main advantage of having validation as a Request Validator instead of validating in the code? My guess it that AWS won't even charge me if the request validation failed, while if I do the validation in the code AWS will charge me for the seconds the code spent validating. Is this guess accurate? |
@AllanOricil I mean, why do something by yourself when you can outsource it to AWS? :) |
Has this feature been released? |
@AntonUspehov but does AWS charge me for the time the Request Validator validation takes or per validation/request? |
@AllanOricil No, only for the API Gateway request, as I know. Lambda won't even be trigger. |
Cool. I will start testing it :D |
This feature has been released. |
I have a question regarding this feature @moelasmar. Typically, one would want to validate for request parametes only. But in order to do this you need to define a RequestModel, would it be better being able to enable parameterValidation from requestParameters instead? |
@santiperone I created another PR for this scenario: #2450 A thumbs up at the PR would be appreciated! |
Team, currently there seems to be a missing piece, when adding request parameters to the SAM template as below, the request parameters get added properly, however the "Request validator" flag doesn't get set and remain None. Our SAM docs for EventSource doesn't seem to have a property to set the Request Validator. Am I missing something? Events:
ServerlessRestApiGETMethod:
Type: Api
Properties:
RestApiId: !Ref Api
Path: /my-path
Method: GET
RequestParameters:
- method.request.querystring.param1:
Required: true
- method.request.querystring.param2:
Required: true cc @moelasmar Cheers |
I had created this PR to address it, but it was not accepted, it is something I would like really implemented, but never got clear directive of better implementation of it. I would be happy to cut a new PR to do it if I have clear direction on it. cc: @moelasmar |
Just switch to cdk or pollumi. Use SAM for testing your lambdas locally. Much easier than write these templates by hand |
Is this topic dead? |
Description: Defining api model to required=true will not add the Request Validator to the method.
with following sam template and sam cli version 0.40
Observed result:
Request Validator in method settings has value "NONE"
Expected result:
Request Validator in method settings has value "Validate body..."
The text was updated successfully, but these errors were encountered: