0

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?

nipy
  • 107
  • 3

1 Answers1

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

  • 1
    A Cloudwatch Events scheduled event (like a cron job for AWS) calling a lambda function that flushes the cache using the API call above would probably work. Might sound complex but it's pretty simple really. Cron -> lambda -> API call – Tim Oct 12 '21 at 07:31
  • 1
    Why not call the function when the upload is finished? That would ensure the cache is cleared exactly when the refreshed data is available. – Erik Norman Oct 12 '21 at 14:22
  • Yep that'd be better if practical. – Tim Oct 12 '21 at 17:16