yr.InvokeOptions.port_forwardings#
- InvokeOptions.port_forwardings: List[PortForwarding]#
Configure port forwarding rules for the sandbox. Each entry specifies a port to be forwarded inside the sandbox environment.
When configured, the port forwarding rules are serialized to JSON and passed to the runtime via
createOptions["network"]. Supports configuring multiple ports simultaneously.- Constraints:
port: Must be an integer in the range [1, 65535].protocol: Must be"TCP"or"UDP". Default is"TCP".
- Raises:
TypeError: Ifportis not anintorprotocolis not astr.ValueError: Ifportis out of range orprotocolis unsupported.
Example:
>>> import yr >>> yr.init() >>> opt = yr.InvokeOptions() >>> opt.port_forwardings = [ ... yr.PortForwarding(port=8080), ... yr.PortForwarding(port=9090, protocol="UDP"), ... ] >>> @yr.invoke(invoke_options=opt) ... def serve(): ... pass
The above configuration produces the following JSON in
createOptions["network"]:{"portForwardings": [{"port": 8080, "protocol": "TCP"}, {"port": 9090, "protocol": "UDP"}]}