Can Serverless offer Parameter validation capability?

I started using Serverless lately (and I also tried AWS SAM before – I will touch upon why I switched to Serverless even though SAM is an AWS native tool).

One feature that API-Gateway can do but I did not see a way to code it up in Serverless is parameter validation at API-Gateway Layer. If a Restful Service (say, ‘/petstores POST’ requires the parameters in the body or header are in certain format) requires to validate certain parameter, AWS provide a way to program the API-Gateway behavior ( See the use scenario in this AWS Blog

Having parameter validated at API-Gateway layer provide the following two benefits:

  1. avoid unnecessary lambda invocations, which is a waste of my budget, if the incoming requests are garbage requests that parameters are in wrong format.
  2. Reduce the bloated logic in my Lambda function that validating certain assumption toward the parameters

However, I don’t see that is offered in Serverles.
- Is there such a capability in Serverless? (I will appreciate if someone show me the pointer)
- If there is no such capability in Serverless out of box, what would be a recommended way for my goal?

1 Like

I don’t think Serverless supports anything like this at the moment. To be honest, I didn’t even know API Gateway could do that, so thanks for posting links!

Personally, I write validation logic inside the handlers and return an error status if validation fails.

I suspect that this wouldn’t be too hard to implement, and as you mentioned, it saves cost and effort writing validation logic inside handlers. I’d open an issue on the repo, it definitely sounds like a cool feature to have!