Score:0

API gateway cache every hour

br flag

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?

Score:1
cn flag

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

Tim avatar
gp flag
Tim
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
Erik Norman avatar
cn flag
Why not call the function when the upload is finished? That would ensure the cache is cleared exactly when the refreshed data is available.
Tim avatar
gp flag
Tim
Yep that'd be better if practical.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.