AWS Serverless Hero. Independent Consultant. Developer Advocate at Lumigo.
Having previously blogged about the untrodden path to enable caching on API Gateway request parameters in the Serverless framework 0.5.X, it’s a little disappointing that it’s still not officially fixed in the 1.X versions…
The problem is two-fold:
A friend pointed me to a neat trick to modify the CloudFormation template that Serverless 1.X auto-generates for you.
After the project is deployed, you can go to CloudFormation and view the template that Serverless has generated. These templates are pretty big (and poorly formatted), so I find it easier to open them up in the Designer view and use that view to navigate to the endpoint I’m looking for.
Once you find the resource template for the endpoint, write down its name. Now go back to the
serverless.yml file in your project, and add the resource name to the
resources section at the bottom. You only need to include fields that you want to update or add to the template.
The CloudFormation syntax for an API Gateway method looks like this:
We also need to fill in some blanks for the
After some trial-and-error, the minimum set of fields I had to add are:
Redeploy with Serverless and the path parameter is enabled for caching:
I hope you have found this post useful, though I’m surprised by the lack of information out there during my research and the lack of official support from the Serverless framework.
You know of a better way to do this, please let me know in the comments.
Like what you’re reading? Check out my video course Production-Ready Serverless and learn how to run a serverless application in production.
We will cover topics including:
and include all the latest changes announced at the recent AWS re:Invent conference!
Create your free account to unlock your custom reading experience.