API gateway cache every hour

My API is set up as follows:

API Gateway > Lambda function > S3

Every hour the S3 content is updated at the same time. How do I configure API gateway to cache the endpoint's responses but serve new content every hour?

For example

  • a get request at 12:15 should use the cached content from 12:00.
  • a get request at 12:55 should use the cached content from 12:00.
  • a get request at 13:01 should use the cached content from 13:00.

The s3 bucket has a path for each hour i.e. my_bucket/2021/10/12/12:00 so maybe this can help?


Solution 1:

You could check out this command to flush the API gateway cache, and execute it once you finished uploading. I haven't tested it myself, though.

https://docs.aws.amazon.com/cli/latest/reference/apigateway/flush-stage-cache.html