runtime_env
The runtime_env is used to declare the runtime environment required for UDF execution, including the Python version, PyPI dependencies, and environment variables. This configuration is serialized as a JSON string and stored in the parameters.runtime_env field of LakeFormation. The Aura engine prepares the environment according to this configuration when running the UDF.
Function
- Ensuring execution: The third-party packages and Python versions required by the UDF are installed on the engine as declared, preventing the issue of "local execution success but remote execution failure."
- Version control: The Python version (3.10/3.11) and specified package version can be fixed to ensure a consistent runtime environment.
- Cross-end synchronization: The environment configuration is persisted with the function metadata and is bound to the function's lifecycle.
When to Use
| Scenario | Usage |
|---|---|
| UDF depends on a third-party Python package. | Declare the package name (for example, ["numpy"]) in pypi/pip. |
| Need to specify a Python version | Set python_version (only 3.11 or 3.10 is supported). |
| Need to inject runtime environment variables | Set env_vars. |
| No special dependency | Pass None. The SDK constructs the default environment (python_version=3.11). |
Construction Methods
runtime_env accepts the following three forms, which the SDK internally unifies into a RuntimeEnv object:
| Input Form | Example | Description |
|---|---|---|
| JSON string | '{"python_version": "3.11", "pypi": ["numpy"]}' | Parsed by json.loads. |
| Mapping/dict | {"python_version": "3.11", "pypi": ["numpy"]} | Directly updated into the internal data structure. |
| None | - | Constructs the default RuntimeEnv with python_version set to 3.11. |
Common Keys
| Key | Type | Description |
|---|---|---|
| python_version | str | Python version. Only 3.11 (default) or 3.10 is supported. Passing other versions raises a ValueError. |
| pypi/pip | list[str] | List of PyPI dependencies. Merged by deduplicating package names. |
| env_vars | dict | Runtime environment variables. |
Default Values and Verification Behavior
- When runtime_env is None, the SDK constructs an empty RuntimeEnv and automatically sets python_version to 3.11.
- If runtime_env provides a python_version, the SDK verifies its value. A ValueError is raised if the value is not 3.11 or 3.10.
- RuntimeEnv is a mutable mapping (like a dictionary) that supports the to_dict(), to_json(), and merge(other) methods. The merge method uses a deep merge strategy: Dictionaries are merged recursively. Lists are merged with deduplication (for keys like pypi/pip/dependencies, deduplication is performed based on package names). For scalar conflicts, the left value takes precedence.
Return Value
Returns a Function object containing the version_id assigned by LakeFormation, resource_uris (OBS package addresses), and parameters (metadata such as the signature and runtime environment).
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot