Dmytro Hrimov
  • Blog
  • About

© 2026 Dmytro Hrimov

  • Privacy Policy
  • Terms & Conditions
← All posts
by Dmytro Hrimov·Posted May 16, 2026·Updated Oct 26, 2026·5 min read

AWS Lambda: Instances and start types

AWSLambdaPython

In this article, we will continue our discussion about lambda functions. Specifically, we will delve into lambda instances, start types, and their relationship.

Hello world lambda

To better understand which code is executed, let's examine a simple 'Hello World' lambda code in Python. The code includes a counter, which we will use to demonstrate the concepts of lambda instances and start types.

Here is the Python code:

# Initialize a counter
count = 0

# Handler method
def handler(event, context):
 # Use the counter defined outside the handler
 global count
 # Increase counter on every execution
 count = count + 1
 # Print the count for visibility
 print(count)

I will be using this lambda code in the explanations that are coming next.

Lambda cold start

When your lambda function is first deployed or is not invoked for a long time, it is called a cold start. During a cold start, AWS first loads your lambda code and all libraries into memory interprets them, executes them, and builds your lambda instance.

You might wonder what code is executed during a cold start. In a Python execution environment, code outside the handler method is executed during the cold start process. Therefore, AWS creates and initializes the count variable during this initialization execution.

The cold start time, or init time, is logged separately in lambda logs. At the end of each lambda execution, AWS will log the so-called report log line, and in it, you may notice the Init Duration: N ms.

Cold start can increase the overall execution time of a lambda function, which is crucial in time-sensitive environments. Therefore, minimizing the number of cold starts or cold start duration is essential to ensure optimal performance.

Lambda handler method

Once the lambda instance is built and ready to handle the execution request, AWS will call the handler method on a prepared lambda instance. The time taken by handler method execution counts as the primary execution time.

Lambda instance reuse

If your lambda is not executing at the moment but has just been invoked, AWS keeps a lambda instance for a little while. Therefore, you can immediately invoke your lambda again, and AWS will execute the handler method only. In this scenario, we call the lambda function in a hot state. As a result, we can expect the count to be greater than one.

Let's see it with our counter. If you invoke the hello world lambda three times in a row, you will see 1, 2, and 3 in the logs. Only the first invocation is a cold start. The next two run the handler method only, on the same instance, and the count value is still there from the previous run.

An instance can be replaced at any time. Every new deployment or configuration change creates new instances, and AWS recycles instances every few hours - even if your lambda is invoked all the time. In all these cases, the next invocation is a cold start again, and the count starts from one.

⚠️

AWS does not say how long an idle instance is kept, so do not build anything on it.

Lambda instances and parallel requests

Here is the tricky part. A lambda instance handles one request at a time. If a new request comes in while all existing instances are busy, AWS spins up a new instance for it, and this new instance goes through a cold start.

Let's go back to our counter. Imagine you send three requests at the same time to a lambda that has no instances yet. AWS creates three instances, each one runs its own cold start, and each one has its own count variable. As a result, all three executions print 1.

So each instance has its own counter, and a new instance starts counting from the beginning. The number of instances running at the same time is your lambda concurrency, and I cover it in AWS Lambda: Concurrency.

Cold and hot start in the logs

Remember the report log line from the cold start section? It is the quickest way to tell a cold start from a hot one. Here is how it looks for a cold start:

REPORT RequestId: 8f5b2c1e-...  Duration: 1.85 ms  Billed Duration: 121 ms  Memory Size: 128 MB  Max Memory Used: 38 MB  Init Duration: 118.32 ms

And here is a hot start on the same instance:

REPORT RequestId: 2a9d7e4b-...  Duration: 1.21 ms  Billed Duration: 2 ms  Memory Size: 128 MB  Max Memory Used: 38 MB

Notice here that Init Duration is only present for the cold start.

ℹ️

Since August 2025, AWS bills the init phase too, so a cold start costs you more than the handler time alone.

What it means in practice

Here are a few things I keep in mind because of it:

  • Put expensive setup outside the handler. Create boto3 clients, database connections, and configuration during the cold start, so hot starts can reuse them.

  • Do not rely on global state between invocations. Instances can be replaced at any time, and parallel requests go to different instances. Keep state that matters in an external store.

  • Keep cold starts short. Import only what you need and keep the deployment package small.

  • If cold starts are not acceptable for you, use provisioned concurrency to keep initialized instances ready - read more about it in AWS Lambda: Concurrency.

Final words

That concludes the second topic of the series on AWS Lambdas. Now you know what happens during a cold start and why your lambda instances do not share state. Please reach out if you have questions or think some information needs to be updated and corrected. Thank you so much for your attention!