Chapter 93: AWS Lambda and Serverless for DevOps
93.3 Runtimes, execution environments and cold starts
Story (fictional teaching scenario). In a fictional Jaipur shop, Sara in Oslo measures the first request after a quiet period. It is slower than the next request because the runtime and imports had to start.
Why
You need to distinguish language support from application code, and startup time from the calculation itself.
What
- Runtime runs a particular language version and connects the event to your handler.
- Execution environment is the isolated place containing the runtime and your code.
- Cold start happens when a new environment must initialize before running the handler.
- Warm reuse means a later invocation can use an existing environment. It is possible, not guaranteed.
- /tmp is scratch storage in an environment, not a shared or durable database.
How
-
Choose a supported runtime, not a preview or deprecated one.
-
Keep imports and dependencies small.
-
Never depend on memory or /tmp surviving.
Example 1: Runtime configuration plan
- Read the input and the code.
Runtime: python3.13
Handler: price.lambda_handler
- Read the result.
Output (illustrative; not executed on AWS)
Language: Python 3.13
Entry: price.py -> lambda_handler
- What each part means:
Runtimeselects the language family.Handlerselects your entry point. The official runtime page currently lists Python 3.13 as supported. This plan is not a provisioning template and was not applied. Local interpreter version can differ from AWS.
Example 2: Why a global counter is not a database
- Read the input and the code.
counter = 0
def handler(event, context):
global counter
counter += 1
return counter
- Read the result.
Output (illustrative; not executed on AWS)
Environment A: 1, then 2
New environment B: 1
- What each part means: The variable belongs to one Python process. A new environment starts again at zero. Multiple environments have separate counters. Do not use it for invoice IDs, duplicate prevention or balances.
Ravindra Bagale's Tip
Warm reuse is an optimization, never a correctness rule.
Warm reuse हा speed चा फायदा आहे; code बरोबर चालण्यासाठी त्यावर अवलंबून राहू नका.
Warm reuse speed का फायदा है, सही result के लिए उस पर निर्भर मत रहो.
Did you understand? Let us try it once more.