title: AWS Lambda function state (zappa)
body: <p>I think to optimize flask app  lambda server by adding internal cache for relatively slow to change data (e.g. site dropdowns might changes few times per year). I use zappa to deploy to lambda. Does it make any sense? Or does it flash memory each time a request processed. I know that I can not <em>rely</em> on aws preserving state, my goal here optimize performance a bit without spending a fortune on some redis instance not to mention ElastiCache.</p>
  
  <p>UPDATE: Yup, the serverless deployment frameworks like zappa recycle the state, so why I should not. Below a hackernoon blog discuss the state recycling in greater details</p>
  
  <p><a href="https://hackernoon.com/write-recursive-aws-lambda-functions-the-right-way-4a4b5ae633b6" rel="nofollow noreferrer">https://hackernoon.com/write-recursive-aws-lambda-functions-the-right-way-4a4b5ae633b6</a></p>
  
  <blockquote>
    <p>Whilst Lambda functions are ephemeral by design, containers are still
    reused for optimization which means you can still leverage in-memory
    states that are persisted through invocations.</p>
  </blockquote>
  
  <p>Not sure can one invalidate such cache, env variables are likely local to lambda instance, http, 
  sns probably difficult/expensive.</p>