Skip to main content

LambdaRuntime

Struct LambdaRuntime 

Source
pub struct LambdaRuntime { /* private fields */ }

Implementations§

Source§

impl LambdaRuntime

Source

pub fn from_backend(backend: Arc<dyn LambdaBackend>) -> Self

Construct a runtime over the supplied backend. Callers that want auto-detection should use Self::auto_detect_docker or Self::new.

Source

pub fn auto_detect_docker(server_port: u16) -> Option<Self>

Auto-detect Docker or Podman. Returns None if neither is available. Override with FAKECLOUD_CONTAINER_CLI env var.

Source

pub fn new(server_port: u16) -> Option<Self>

Backwards-compatible alias for Self::auto_detect_docker. Callers across the workspace use ContainerRuntime::new(port).

Source

pub async fn new_k8s( server_port: u16, internal_token: String, ) -> Result<Self, K8sBackendError>

Construct a runtime backed by the Kubernetes backend. Reads configuration from env vars (FAKECLOUD_K8S_SELF_URL, FAKECLOUD_K8S_NAMESPACE, etc.) and connects to the cluster via in-cluster service account or kubeconfig. Hard-fails on any configuration or connectivity issue — we don’t silently fall back to Docker because the operator explicitly opted in to K8s.

internal_token is the bearer token the artifact endpoints on the fakecloud server expect from Pod init containers — caller must register the same token on those endpoints.

Source

pub fn cli_name(&self) -> &str

Source

pub async fn prepull_for_function( &self, func: &LambdaFunction, ) -> Option<Result<(), RuntimeError>>

Background pre-warm hook: pull the image a Zip-package function will need at invoke time, or the ImageUri of an Image-package function. The first cold pull of an AWS base image (~700 MB) frequently exceeds the AWS CLI default 60s read timeout, surfacing to users as Connection was closed (issue #1539). Call after CreateFunction persists so the warm path is ready before the caller turns around and calls Invoke.

Returns None if the function has no resolvable image (e.g. an unsupported runtime string we can’t map to a base image). Otherwise returns the result of the backend’s prepull_image — callers log failures and move on, since invoke time still re-attempts the pull as a fallback.

Source

pub async fn invoke( &self, func: &LambdaFunction, payload: &[u8], layers: &[Vec<u8>], ) -> Result<Vec<u8>, RuntimeError>

Invoke a Lambda function, starting an instance if needed. Layer ZIPs are extracted into /opt of the runtime sandbox; AWS base images already include /opt/python, /opt/nodejs/node_modules, /opt/lib, and /opt/bin on the right import paths.

Reserves a warm instance for the call (one in-flight invocation per instance — the RIE crashes on overlap, issue #1644). If the instance is unreachable (dead Pod/container from a node drain, OOM, or prior crash) it is evicted and the call retried (up to four times) against a freshly cold-started instance, so a dead instance can’t wedge the function permanently.

Source

pub async fn invoke_streaming( &self, func: &LambdaFunction, payload: &[u8], layers: &[Vec<u8>], ) -> Result<StreamingInvocation, RuntimeError>

Invoke a Lambda function and yield the raw HTTP body as a stream of byte chunks. Each chunk corresponds to one HTTP frame the RIE flushed to the wire — for streaming-aware handlers this preserves the chunk boundaries the function emitted. Buffered handlers come back as a single chunk, which is still a valid streamed response.

The reserved instance’s busy guard travels with the returned StreamingInvocation so the slot stays held until the caller finishes draining the stream.

Source

pub async fn stop_container(&self, function_name: &str)

Stop and remove every warm instance for a specific function.

Source

pub async fn stop_all(&self)

Stop and remove all warm instances (used on server shutdown or reset).

Source

pub fn list_warm_containers( &self, lambda_state: &SharedLambdaState, ) -> Vec<Value>

List all warm instances and their metadata for introspection. One row per running instance — a function scaled to several warm instances appears once per instance.

Source

pub async fn evict_container(&self, function_name: &str) -> bool

Evict (stop and remove) every warm instance for a specific function. Returns true if at least one instance was evicted.

Source

pub async fn run_cleanup_loop(self: Arc<Self>, ttl: Duration)

Background loop that stops instances idle longer than ttl.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more