title: How to optimize AWS Lambda?
body: <p>I'm currently building web API using AWS Lambda with <a href="https://github.com/serverless/serverless" rel="noreferrer">Serverless Framework</a>.</p>
  
  <p>In my lambda functions, each of them connects to Redis (elasticache) and RDB (Aurora, RDS) or DynamoDB to retrieve data or write new data.
  And all my lambda functions are running in my VPC.</p>
  
  <p>Everything works fine except that when a lambda function is first executed or executed a while after last execution, it takes quite a long time (1-3 seconds) to execute the lambda function, or sometimes it even respond with a gateway timeout error (around 30 seconds), even though my lambda functions are configured to 60 seconds timeout.</p>
  
  <p>As stated in <a href="https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/" rel="noreferrer">here</a>, I assume 1-3 seconds is for initializing a new container. However, I wonder if there is a way to reduce this time, because 1-3 seconds or gateway timeout is not really an ideal for production use.</p>