how to set up caching in a lambda?

0

I have an application that reads some data from s3, say an lambda reads from s3 everytime it runs . is there any caching mechanism implemented between s3 and lambda, such that multiple invocations of lambda, if there are any, don't have to download/read the data , but will be available in cache. also, if the data is updated in s3, we update cache as well.

asked 2 months ago240 views
2 Answers
1

Check out this engaging post on caching data and configuration settings with AWS Lambda extensions: Caching Data and Configuration Settings with AWS Lambda Extensions.

profile picture
EXPERT
answered 2 months ago
0

There is no builtin caching mechanism as you describes. You have a few options:

  1. In the Lambda function itself, save the data that you read in a static variable. This will allow you to read it only once per function instance. Each instance will need to read its own copy. You do not have an automatic way to refresh the cache. You can include some TTL that if it passed, you will get the file again next invocation.
  2. Use some write aside cache, like DynamoDB (Depending on the side of the data, as it supports up to 400 KB per item), or Elasticach. Your functions will first check if it is in the cache, if it is, they read it from there. If it is not, they read from S3 and update the cache. To update the cache when the files in S3 are updated, you need a second function that waits for object updates and it will update the cache.
profile pictureAWS
EXPERT
Uri
answered 2 months ago
profile picture
EXPERT
reviewed a month ago
  • @Uri - thanks . do you know of any blogs/examples of similar use case that you can point me to.

  • Found this external blog. I think it is relevant. Also this one.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions