Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda