Custom Runtimes in AWS Lambda
Instruction: Explain the process of creating and using custom runtimes in AWS Lambda, and describe a scenario where a custom runtime would be necessary.
Updated
Official answer
A custom runtime is the program that initializes the function, obtains invocation events and calls the handler. It can be bundled with the function or supplied in a layer; it is not necessarily a layer.
For a standard Lambda function using an OS-only runtime:
- Build compatible Linux binaries and dependencies for the selected architecture. Prefer a maintained runtime interface client when one supports the language.
- Select a supported OS-only runtime, such as
provided.al2023. Check its current support lifecycle instead of copying the oldprovidedorprovided.al2choices. - Supply an executable
bootstrapat the package root or in a layer. It loads the handler and implements the Runtime API loop: obtain the next event, retain its request ID/context, call the handler, then report the response or invocation error. Report initialization failures through the initialization-error API and exit. - Test missing/non-executable bootstrap, initialization failure, successful and failed handler calls, repeated invocations and request-state isolation. Deploy only after checking dependencies, permissions and observability in the target environment.
AWS_LAMBDA_EXEC_WRAPPER configures supported managed-runtime wrapper scripts; AWS explicitly does not support those wrapper scripts for the OS-only provided family. Use the custom runtime's bootstrap instead.
A suitable example is a maintained Rust or Go binary with a compatible interface client. Owning a custom runtime also means owning language/dependency patching and compatibility. Managed Instances support concurrent invocations within one environment and require additional thread-safe handling; the sequential standard-function loop alone is not a complete implementation for that mode.
Sources
Custom runtime requirements; OS-only runtime choices; wrapper-script support restrictions.