Prevent non-200 response caching in AWS API Gateway

How do I disable non-200 OK response cache in the API.

For one of our API endpoints, we have implemented our optional throttle mechanism and we send a 429 HTTP response.

The goal is for the client to repeat the request after a short time, when the server is ready to execute it, but now it happens that the API gateway caches the initial response and continues to send it from the cache.

+4
source share
1 answer

According to the answer to Can the AWS API cache cache invalidate certain entries based on the contents of the response? The API gateway cache does not seem to have functionality for simply "sometimes" caching the result. The documentation shows a way to force the client to make a request that will ignore the existing cache (by installation Cache-Control: max-age=0), but not show the way for the server to say that β€œthis is a one-time response that cannot be cached.

The first thing that, in my opinion, is worth a try is to specify the type header Cache-Control: max-age=0in the error response in order to try to check if it works. The AWS API Gateway uses CloudFront under the hood to distribute it, so it can just work.

If this does not work, other options include:

  • AWS API. , CloudFront , .
  • ( , API Throttling), , "" , , , . ( API- - ), back-end.
  • 429 , , " " Cache-Control: max-age=0, "" , . , , , , , , "".
  • TTL . , , 60 , 60- TTL , 429 . , , , , "", , 429 TTL. TTL "" "".
+2

Source: https://habr.com/ru/post/1684472/


All Articles