Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Does lambda persist any data in memory?

I have below code in AWS lambda:


const cache = {};

exports.handler = async (event) => {
    // TODO implement
    if (cache[event.key]) {
        console.log('read from cache');
        return cache[event.key];
    }
    console.log('generate value');
    cache[event.key] = Math.random()
    
    return cache[event.key];
};

when I run the the lambda and I can see read from cache on the log which means the lambda cache some values in cache memory. Does the lambda persist its memory when it becomes warm? Does it mean I can make use of this memory for some caching in order to improve performance?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

It is possible to persist things between invocations of Lambda (assuming that the invocations hits the same MicroVM), but your application should not rely on it for performance.

There is no guarantee for how long it will persist on the MicroVM, also be aware by the volume you store in memory as this may impact the performance of your Lambda if no enough memory is available for it. If you're looking to improve performance then take a look at some of these options:

  • Systems Manager Parameter Store - Use this option if you need to store a single key/value combination.
  • DynamoDB - Use this option if you need a number of key/value combinations.
  • Elasticache - Use this option if you need an in memory key/value store with support for many complex data types. This would require the Lambda being added to the VPC.
over 4 years ago · Santiago Trujillo Report

0

Lambda container remains alive even after the invocation is complete. So, whatever data loaded in the container's memory will be available throughout the Lambda container lifecycle.

So, this memory can be used as leverage for caching.

Data in the cache would be useful if your application is read-extensive. For example in a case where the same username has to be fetched from Database, we can cache the username for future invocations. Thus, mitigating the cost of DB query.

Above approach seems to help but there are few downsides as well:

  1. The lack of synchronization between different lambda containers created by multiple invocations of the lambda would cause to store the same data and many misses of already store data in the cache.
  2. If the data in the cache has increased to a level of memory exhaustion needed for lambda for processing could cause to stop lambda working altogether.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!