Is there any way to make SAM less verbose?
I am looking at my template, it's 400 lines of code (swagger alone) for what's basically 4 REST endpoints. That's unmanageable. Is there a way we can make API Gateway + Lambda more succinct by having reasonable defaults? This is more of an open question, to gain ideas and insight, may be the correct solution will be a different project which takes as input API definition and outputs a SAM template.
What I would like to see as a definition is something along these lines (assume JSON):
{
"accepts":"application/json",
"produces":"application/json",
"CORS":"*",
"authorizer":"authorize.handler"
"endpoints":
[{"path": "/{resourceName}", "method":"GET", "handler":"index.getAll"},
{"path": "/{resourceName}/{resourceId}", "method":"GET", "handler":"index.getOne"},
{"path": "/{resourceName}/{resourceId}", "method":"POST", "handler":"index.createOne"},
{"path": "/{resourceName}/{resourceId}", "method":"PUT", "handler":"index.updateOne"},
{"path": "/{resourceName}/{resourceId}", "method":"DELETE", "handler":"index.deleteOne"},
{"path": "/testResource/{resourceId}/someAction", "method":"POST", "handler":"testResource.someAction"}]
}
SAM is already much less verbose than CloudFormation. It sounds like your issue is more with Swagger than SAM? At the end of the day, you shouldn't have to deal with your generated templates (much) on a day-to-day basis - how often do you expect your API definition to change? Optimizing for lower template character count would be a relatively low priority for me.
While I'm new to Swagger, my impression is that having something to generate it is the ideal solution (I certainly don't want to write it by hand). While this doesn't necessarily reduce the verbosity (which is part of the language definition - reduced verbosity will equate to reduced functionality) it does reduce the complexity of managing it.
Another option would be to use Serverless. While it has its own pros and cons, the HTTP endpoint definition is very similar for what you've expressed.
I switched to the Serverless framework, it's much easier to work with and saves me development time.