Ravindra BagaleCourses & study guides मराठी

Chapter 93: AWS Lambda and Serverless for DevOps

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.

Runtimes, execution environments and cold starts
Runtimes, execution environments and cold starts

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

  1. Choose a supported runtime, not a preview or deprecated one.

  2. Keep imports and dependencies small.

  3. Never depend on memory or /tmp surviving.

Example 1: Runtime configuration plan

  1. Read the input and the code.
Runtime: python3.13
Handler: price.lambda_handler
  1. Read the result.

Output (illustrative; not executed on AWS)

Language: Python 3.13
Entry: price.py -> lambda_handler
  1. What each part means: Runtime selects the language family. Handler selects 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

  1. Read the input and the code.
counter = 0
def handler(event, context):
    global counter
    counter += 1
    return counter
  1. Read the result.

Output (illustrative; not executed on AWS)

Environment A: 1, then 2
New environment B: 1
  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.

Did you understand? Let us try it once more.