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.

질문됨 3달 전306회 조회
2개 답변
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
전문가
답변함 3달 전
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
전문가
Uri
답변함 3달 전
profile picture
전문가
검토됨 한 달 전
  • @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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠