Lambda Core Vocabulary
coreintermediateA Lambda function runs your handler code in a managed execution environment that goes through Init (bootstrap + your outside-handler code), Invoke (runs the handler per request), and Shutdown (cleanup) phases. Memory (128 MB–10,240 MB) also scales CPU. A version is an immutable snapshot; an alias is a mutable pointer to a version, letting you shift traffic without changing the invoker.
Think of it as
The execution environment is a kitchen that gets set up once (Init — hire staff, stock shelves) and then serves many orders (Invoke) before eventually closing (Shutdown). A version is a signed, dated recipe card that never changes; an alias is a "today's special" sign you can repoint to a different recipe card without reprinting the menu.
What we're doing: See code placement determine whether it runs once (Init) or on every request (Invoke).
- 1
- The import runs during Init — once per execution environment, not once per request.
- 2
- Creating the S3 client here means every subsequent warm invocation reuses the same client instead of recreating it.
- 4
- Only code inside the handler runs during the Invoke phase, bounded by the function's configured timeout.
Why this works: Placing expensive setup (client creation, DB connections) outside the handler is what makes warm invocations fast — that code runs once during Init and is reused across every subsequent Invoke on the same execution environment.
Creating a new SDK client inside the handler on every invocation
Wrong
Better
What you see: Every warm invocation still pays the cost of re-establishing an SDK client (and, for a database, a new connection), even though the execution environment is already running and could reuse one.
Why: Code inside the handler runs on every Invoke, regardless of whether the environment is warm — only code placed outside the handler, at module scope, benefits from the Init-once/Invoke-many-times lifecycle.
- Init — bootstrap + outside-handler code
- leads to Invoke (ready)
- Invoke — handler runs per request
- leads to Reused? (finishes)
- Reused? — warm start if yes
- leads to Invoke (yes — warm start)
- leads to Shutdown (no — eventually)
- Shutdown — cleanup, eventually
Remember: Init runs once per environment (bootstrap + outside-handler code); Invoke runs per request, bounded by timeout. Version = immutable snapshot; alias = mutable pointer callers actually target.
See also: invocation models · cold starts and concurrency

