Closed itsTeknas closed 4 years ago
Hi @itsTeknas,
This plugin enables caching at the API Gateway level. CloudFront sits in front of that:
CloudFront has its own caching at edge locations around the world, which you can read more about here.
The header X-Cache
tells you whether the response came from the CloudFront cache.
To figure out whether you're getting a response from the API Gateway cache, you can also add a date into your response and check whether it stays the same with subsequent requests:
module.exports.getSurvey = async event => {
return {
statusCode: 200,
headers: {
// the other headers
'My-Custom-Date-Header': new Date()
},
body: JSON.stringify({"hello":"world"}),
};
};
Hey, thanks for the clarification :) So we're not using CloudFront Cache but using ApiGW cache is it ?
Is there a way to use and configure CloudFront cache also ? I believe you do create a cloudfront distribution.
This plugin does not create a CloudFront distribution, it just enables API Gateway caching, and that creates a cache cluster. I've not used any plugins that configure CloudFront, but there probably are some out there.
i implemented this for a simple api in serverless + aws lambda with caching enabled
i can confirm the responses are cached because there are no lambda execution logs for subsequent hits. But in the response, the header X-Cache says "Miss from cloudfront"
config file:
handler:
don't know if this has anything to do with this plugin or a quirk of cloudfront.