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.

Context: This question evaluates the candidate's knowledge of AWS Lambda's custom runtime feature, including how to create a custom runtime and the types of scenarios that would require one, enhancing the flexibility and capability of Lambda functions.

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:

  1. Build compatible Linux binaries and dependencies for the selected architecture. Prefer a maintained runtime interface client when one supports the language.
  2. Select a supported OS-only runtime, such as provided.al2023. Check its current support lifecycle instead of copying the old provided or provided.al2 choices.
  3. Supply an executable bootstrap at 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.
  4. 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.

Related Questions