How to enable proper caching for an API Gateway endpoint?
I've enabled the API cache (see screenshot), but when I request the URL, the response time stayed the same as before.
I tried enabling the API cache option:
And configured the Cache-Control header:
And also enabled caching by a query parameter:
Caching in API Gateway is not implemented via CloudFront. API Gateway creates a CloudFront distribution on your behalf when you create your API, but caching is actually implemented via use of dedicated caching infrastructure. Even with caching enabled you will continue to see "cache miss" headers from CloudFront.
I found the AWS forum provided some more insight, incase it helps anyone else.
API Gateway integrates with CloudFront behind the scenes. We automatically create a global CloudFront distribution for your APIs in order to reduce the latency perceived by end users. However, the API Gateway cache is handled in the region where API Gateway runs and your API is deployed. Requests are accepted by the CloudFront PoP and then sent to the API Gateway in its origin region, that's where API Gateway will check against its cache and return a cached response if possible. At the moment API Gateway does not use CloudFront's cache at the edge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With